动画WPF窗口左,右一个晃动的影响? [英] Animate a WPF Window left and right with a shake effect?
问题描述
可能有人请告诉我如何从当前位置动画的窗口。我要寻找一个晃动的影响它只是左摇窗和右边说5到6倍。
Could someone please show me how to animate a window from its current position. I am looking for a shake effect which simply shakes the window left and right say 5 to 6 times.
据我了解,我需要使用Animation.By。这是我已经开始,但我不是越来越远。
I understand that I need to use Animation.By. This is something I have started but am not getting far.
然而,这是行不通的。
<Storyboard x:Key="sbShake1" FillBehavior="Stop">
<DoubleAnimation Storyboard.TargetName="W1" Storyboard.TargetProperty ="(Window.Left)"
By="10" Duration="0:0:1">
</DoubleAnimation >
</Storyboard >
我设法得到正确的防抖效果,但我不能从windows做的当前位置。
I have managed to get the right shake effect but I cannot do it from the windows current position.
<Storyboard x:Key="sbShake" RepeatBehavior ="00:00:01" SpeedRatio ="25" >
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty ="Left">
<SplineDoubleKeyFrame KeyTime ="00:00:00.1000000" Value ="-10"/>
<SplineDoubleKeyFrame KeyTime ="00:00:00.3000000" Value ="0"/>
<SplineDoubleKeyFrame KeyTime ="00:00:00.5000000" Value ="10"/>
<SplineDoubleKeyFrame KeyTime ="00:00:00.7000000" Value ="0"/>
</DoubleAnimationUsingKeyFrames >
</Storyboard >
所有的帮助将是AP preciated。
All help would be appreciated.
推荐答案
您窗口的左属性设置为500,并添加此code:
Set the Left property of your window to 500 and add this code:
<Window.Triggers>
<EventTrigger RoutedEvent="Window.MouseDown" >
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetProperty="Left">
<DoubleAnimation From="500" To="515" Duration="0:0:0.05"
AutoReverse="True" RepeatBehavior="3x"
FillBehavior="Stop"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Window.Triggers>
您应该设置窗口
手动当你不提财产左
从=X
,否则将其设置为自动,当你试图动摇你的窗口左侧的值为NaN和会抛出异常。
You should set the property Left
of Window
manually when you don't mention From="x"
otherwise it set to Auto and when you try to shake your window the value of Left is NaN and an exception will be thrown.
这篇关于动画WPF窗口左,右一个晃动的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!