[英]In WPF, how can I animate different objects with different storyboard simultaneously?
假設我有兩個像AnimateHorizontally和AnimateVertically這樣的動畫方法
public void AnimateHorizontally(FrameworkElement element, double XMoveStart, double XMoveEnd, int milli)
{
BackEase eEase = new BackEase();
Storyboard sb = new Storyboard();
DoubleAnimation daX = new DoubleAnimation(XMoveStart, XMoveEnd, new Duration(new TimeSpan(0, 0, 0, 0, milli)));
daX.EasingFunction = eEase;
Storyboard.SetTargetProperty(daX, new PropertyPath("(Canvas.Left)"));
sb.Children.Add(daX);
element.BeginStoryboard(sb);
}
public void AnimateVertically(FrameworkElement element, double YMoveStart, double YMoveEnd, int milli)
{
ElasticEase eEase = new ElasticEase();
Storyboard sb = new Storyboard();
DoubleAnimation daY = new DoubleAnimation(YMoveStart, YMoveEnd, new Duration(new TimeSpan(0, 0, 0, 0, milli)));
daY.EasingFunction = eEase;
Storyboard.SetTargetProperty(daY, new PropertyPath("(Canvas.Top)"));
sb.Children.Add(daY);
element.BeginStoryboard(sb);
}
當我將其應用於對象A時,它會從XMoveStart和XMoveEnd水平移動。 如果我有一個對象B,並且我希望對象B應用ElasticEase並垂直移動。
對象A和對象B上的動畫應同時且平穩地開始播放,我該怎么做?
只需致電
AnimateVertically(A)
AnimateHorizontally(B)
如此平滑並不可行,而且似乎它們不是同時發生的。 有人可以幫忙嗎? 我不必使用Storyboard,如果還有其他一些動畫方法可以完成任務,那么我也可以使用它們。
就在這里。 您只需要在一個情節提要板中放置多個動畫並設置動畫的TargetName-Property:
這里是一個示例故事板。 注意TargetName-Properties:
<Storyboard x:Name="FromMainToBack">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ScaleContainerGrid" Storyboard.TargetProperty="ScaleY">
<LinearDoubleKeyFrame KeyTime="0:0:0.2" Value="0.8"/>
<LinearDoubleKeyFrame KeyTime="0:0:1.2" Value="0.8"/>
<LinearDoubleKeyFrame KeyTime="0:0:1.5" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ScaleContainerGrid" Storyboard.TargetProperty="ScaleX">
<LinearDoubleKeyFrame KeyTime="0:0:0.2" Value="0.8"/>
<LinearDoubleKeyFrame KeyTime="0:0:1.2" Value="0.8"/>
<LinearDoubleKeyFrame KeyTime="0:0:1.5" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimation BeginTime="0:0:0.2" Duration="0:0:0.5" From="0" To="90" Storyboard.TargetName="planeProjectionMain" Storyboard.TargetProperty="RotationY">
<DoubleAnimation.EasingFunction>
<BackEase EasingMode="EaseIn"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation BeginTime="0:0:0.7" Duration="0:0:0.5" From="270" To="360" Storyboard.TargetName="planeProjectionBack" Storyboard.TargetProperty="RotationY">
<DoubleAnimation.EasingFunction>
<BackEase Amplitude="0" EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.