Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Enlarge image on mouseenter in wpf

$
0
0
I am really new to wpf. The image I have inserted is supposed to enlarge on mouse over. I have written this thing multiple times, but I really just don't know what I am doing. When I mouseover the image, I get "Object reference not set to an instance of an object". I really need and want to learn this. I greatly appreciate any help, tips, or hints. Thanks in advance for your time!

<Window x:Class="_25._6_Image_Reflector___MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Reflection" Height="600" Width="868" WindowStartupLocation="CenterScreen">
    <window.Resources>
        &lt!-- This storyboard will make the image grow to double its size in 0.2 seconds -->
        <Storyboard x:Key="expandStoryboard">
            <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="2" Duration="0:0:0.2" />
            <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="2" Duration="0:0:0.2" />
        </Storyboard>
        &lt!-- This storyboard will make the image revert to its original size -->
        <Storyboard x:Key="shrinkStoryboard">
            <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1" Duration="0:0:0.2" />
            <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="1" Duration="0:0:0.2" />
        </Storyboard>
    </window.Resources>

    <StackPanel Orientation="Horizontal">
        <StackPanel Orientation="Vertical">
            <Border BorderBrush="White" BorderThickness="5" MouseEnter="borderEnter">
                <Image Source="Fahrenheit.jpg" Width="200" Height="300" Stretch="Fill" x:Name="Fahrenheit"></Image>
                <Border.BitmapEffect>
                    <BitmapEffectGroup>
                        <DropShadowBitmapEffect Color="Black" Direction="20" ShadowDepth="25" Softness="1" Opacity="0.5"/>
                    </BitmapEffectGroup>
                </Border.BitmapEffect>
            </Border>
            
            <Border Width="210" Height="300" BorderThickness="5" BorderBrush="White">
                <Border.Background>
                    <VisualBrush Visual="{Binding ElementName=Fahrenheit}">
                        <VisualBrush.Transform>
                            <ScaleTransform ScaleX="1" ScaleY="-1" CenterX="200" CenterY="150"></ScaleTransform>
                        </VisualBrush.Transform>
                    </VisualBrush>
                </Border.Background>
                
                <Border.OpacityMask>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Offset="0" Color="Black"></GradientStop>
                        <GradientStop Offset="0.6" Color="Transparent"></GradientStop>
                    </LinearGradientBrush>
                </Border.OpacityMask>
                
                <Border.Triggers>
                    <EventTrigger RoutedEvent="Mouse.MouseEnter">
                        <BeginStoryboard>
                            &lt!--Where do I go from here?-->
                        </BeginStoryboard>
                    </EventTrigger>       
                </Border.Triggers>
            </Border>
        </StackPanel>    
    </StackPanel>
</Window>

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void borderEnter(object sender, MouseEventArgs e)
        {
            Storyboard s = (Storyboard)TryFindResource("borderEnter");
            s.Begin();
        }

        private void borderExit(object sender, MouseEventArgs e)
        {
            Storyboard s = (Storyboard)TryFindResource("borderEnter");
            s.Stop();
        }
    }



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>