<Window x:Class="ImageZoomTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowState="Maximized">
<Grid Margin="0" Name="gridMain">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.7*"/>
<ColumnDefinition Width="0.3*"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0">
<Image Name="imageLarge" Source="Image\1600XMAS_3001.jpg" Width="800" Height="500">
<Image.RenderTransform>
<RotateTransform x:Name="imageLargeRotateTransform" Angle="0"/>
</Image.RenderTransform>
</Image>
</DockPanel>
<DockPanel Grid.Column="1">
<Button Name="btnRotateClockwise" Content="Rotate clockWise" DockPanel.Dock="Bottom" >
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="imageLargeRotateTransform" Storyboard.TargetProperty="Angle" By="90" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</DockPanel>
</Grid>
</Window>
上面这段代码的效果是点击一下button,图片顺时针旋转90度,动画时间是1秒针。如果点击按钮时候比较慢,两次点击的间隔大于1秒,运行正常。但是如果点击的很快,第一次点击的动画还没有结束,第二次点击的动画又开始了,图片最后停止时停留的角度就有问题了。xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowState="Maximized">
<Grid Margin="0" Name="gridMain">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.7*"/>
<ColumnDefinition Width="0.3*"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0">
<Image Name="imageLarge" Source="Image\1600XMAS_3001.jpg" Width="800" Height="500">
<Image.RenderTransform>
<RotateTransform x:Name="imageLargeRotateTransform" Angle="0"/>
</Image.RenderTransform>
</Image>
</DockPanel>
<DockPanel Grid.Column="1">
<Button Name="btnRotateClockwise" Content="Rotate clockWise" DockPanel.Dock="Bottom" >
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="imageLargeRotateTransform" Storyboard.TargetProperty="Angle" By="90" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</DockPanel>
</Grid>
</Window>
解决这种现象的方法很简单,只要在BeginStoryboard里面设置HandoffBehavior属性为Compose就可以了: <BeginStoryboard HandoffBehavior ="Compose" >。