我有以下故事板:
<Window.Resources>
<Storyboard x:Key="ButtonsAnim">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="topRightButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="-100"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="topRightButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="100"/>
...
它基本上在画布中移动一些按钮。
这是启动动画的代码:
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Storyboard sb = (Storyboard)Resources["ButtonsAnim"];
storyBoard = sb;
storyBoard.Begin(this, true);
}
我要做的是在单击隐藏窗口的按钮时重置动画。当窗口重新出现时,动画应该从头开始。
我尝试在应用程序重新出现时使用 storyBoard.Begin(this, true) ,但在最初的几毫秒内,按钮位于最后一个位置。
然后我在隐藏窗口之前尝试了 storyBoard.seek(TimeSpan.Zero) 但它失败了:
System.Windows.Media.Animation 警告:6:无法执行操作,因为指定的情节提要从未应用于此对象以进行交互式控制。行动='寻找'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='24901833'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='System.Windows.Media.Animation.Storyboard'; TargetElement.HashCode='24901833'; TargetElement.Type='System.Windows.Media.Animation.Storyboard'
在隐藏窗口之前,我还尝试了 storyBoard.remove(this),效果相同:按钮位于最后一个位置。
有任何想法吗?
谢谢你。