当另一个动画运行时,避免使用WPF Storyboard动画

时间:2016-05-19 11:44:49

标签: wpf storyboard

我是WPF Storyboard的新手,我定义了以下两个故事板。

<Storyboard x:Key="sbShowLeftMenu" Completed="Storyboard_Completed"  >
    <ThicknessAnimation Storyboard.TargetProperty="Margin" From="-100,0,0,0" To="0,0,0,0" DecelerationRatio=".9" Duration="0:0:1" />
</Storyboard>
<Storyboard x:Key="sbHideLeftMenu" Completed="Storyboard_Completed">
    <ThicknessAnimation Storyboard.TargetProperty="Margin" From="0,0,0,0" To="-100,0,0,0" AccelerationRatio=".9" Duration="0:0:1" />
</Storyboard>

我发现两种情况同时被触发的情况。如何确保只在另一个完成后触发一个?我知道有完成的事件,但不知道如何使用它。

1 个答案:

答案 0 :(得分:0)

您的XAML(已编辑)

<Storyboard x:Key="sbShowLeftMenu" Completed="Storyboard_Completed"  >
    <ThicknessAnimation Storyboard.TargetProperty="Margin" From="-100,0,0,0" To="0,0,0,0" DecelerationRatio=".9" Duration="0:0:1" />
</Storyboard>
<Storyboard x:Key="sbHideLeftMenu">
    <ThicknessAnimation Storyboard.TargetProperty="Margin" From="0,0,0,0" To="-100,0,0,0" AccelerationRatio=".9" Duration="0:0:1" />
</Storyboard>

请注意,我已删除了第二个Storyboard_Completed(除非您需要它)。

代码隐藏(.xaml.cs)

private void Storyboard_Completed(...)
{
    sbHideLeftMenu.Begin();
}