Here is an example that does what I think you want:
<Window x:Class="WpfApplication.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="600" Width="600"> <Window.Resources> <Storyboard x:Key="ScaleImageStoryboard"> <DoubleAnimation Duration="0:0:0.5" From="300" To="400" Storyboard.TargetName="Image" Storyboard.TargetProperty="Height"/> <DoubleAnimation Duration="0:0:0.5" From="300" To="400" Storyboard.TargetName="Image" Storyboard.TargetProperty="Width"/> </Storyboard> </Window.Resources> <Grid> <Image Name="Image" Source="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg" Stretch="Fill" Width="300" Height="300"> <Image.Triggers> <EventTrigger RoutedEvent="Image.MouseDown"> <BeginStoryboard Storyboard="{StaticResource ScaleImageStoryboard}"/> </EventTrigger> </Image.Triggers> </Image> </Grid> </Window>
Here the image starts with 300x300 px. When the Image.MouseDown event is fired, the trigger starts a storyboard that resizes the image to 400x400 for half the second period.
However, if you need an effect that temporarily affects the size of the image and does not affect the layout, you should use:
<Window x:Class="WpfApplication.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="600" Width="600"> <Window.Resources> <Storyboard x:Key="ScaleImageStoryboard"> <DoubleAnimation Duration="0:0:0.2" From="1" To="1.2" AutoReverse="True" Storyboard.TargetName="ScaleImage" Storyboard.TargetProperty="ScaleX"/> <DoubleAnimation Duration="0:0:0.2" From="1" To="1.2" AutoReverse="True" Storyboard.TargetName="ScaleImage" Storyboard.TargetProperty="ScaleY"/> </Storyboard> </Window.Resources> <Grid> <Image Name="Image" Source="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg" Stretch="Fill" Width="300" Height="300" RenderTransformOrigin="0.5, 0.5"> <Image.RenderTransform> <ScaleTransform x:Name="ScaleImage"/> </Image.RenderTransform> <Image.Triggers> <EventTrigger RoutedEvent="Image.MouseDown"> <BeginStoryboard Storyboard="{StaticResource ScaleImageStoryboard}"/> </EventTrigger> </Image.Triggers> </Image> </Grid> </Window>
source share