Wpfanimation – 就像在iOS上晃动图标一样
我想在wpf中有一个图像animation,图像轻微抖动以便删除它,就像iOS中的应用程序一样。 你知道什么可以帮助吗? 一些已经build成的东西? 非常感谢。
这是一个摇动button文本的完整示例。 你应该能够适应这个动摇的形象,并改善它使用缓和function。
<Grid.Resources> <ControlTemplate x:Key="ShakingButtonTemplate" TargetType="Button"> <Border Margin="5" BorderBrush="Aquamarine" BorderThickness="5" CornerRadius="5"> <ContentPresenter HorizontalAlignment="Center" Content="{TemplateBinding Content}"> <ContentPresenter.RenderTransform> <TransformGroup> <TranslateTransform x:Name="Position"/> </TransformGroup> </ContentPresenter.RenderTransform> </ContentPresenter> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard x:Name="ShakeIt"> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Position" Storyboard.TargetProperty="X" RepeatBehavior="5x" > <EasingDoubleKeyFrame KeyTime="0:0:0.05" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="2"/> <EasingDoubleKeyFrame KeyTime="0:0:0.15" Value="0"/> <EasingDoubleKeyFrame KeyTime="0:0:0.20" Value="-2"/> <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="0"/> </DoubleAnimationUsingKeyFrames> <!-- <DoubleAnimation Storyboard.TargetName="Position" Storyboard.TargetProperty="X" From="-2" To="2" Duration="0:0:0:0.1" AutoReverse="True" RepeatBehavior="10x"> </DoubleAnimation> --> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <Style x:Key="ShakingButton" TargetType="Button"> <Setter Property="Template" Value="{StaticResource ShakingButtonTemplate}"/> </Style> </Grid.Resources> <StackPanel> <Button Style="{StaticResource ShakingButton}" Content="This is a button" /> </StackPanel>