我在MainWindow中有一个故事板如下:
<Storyboard x:Key="OnMouseLeftButtonDown1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever" DecelerationRatio="1" Storyboard.TargetName="ellipse">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
在同一个窗口中我有一个按钮来调用这个StoryBoard并同时打开一个新窗口,如下所示:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
Storyboard sb= this.Resources["OnMouseLeftButtonDown2"] as Storyboard;
if (sb != null)
sb.Begin(this);
Window2 win = new Window2();
win.Show();
}
现在当它显示Window2我希望使用按钮控件停止故事板[“OnMouseLeftButtonDown2”]时,您是否有任何建议如何解决这一步?
Tahnsk非常关注你,
干杯
答案 0 :(得分:1)
嗨,我想你想从新窗口停止故事板 - 对吧? 我会建议这样的事情:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
Storyboard sb= this.Resources["OnMouseLeftButtonDown2"] as Storyboard;
if (sb != null)
sb.Begin(this);
Window2 win = new Window2();
win.StopStoryboardAction = () => sb.Stop();
win.Show();
}
只需为您的新窗口提供操作的公共属性:
public Action StopStoryboardAction { get; set; }
在新窗口内打电话
if (StopStoryboardAction != null) StopStoryboardAction();
这样可以减少一些依赖项。
PS:
win.StopStoryboardAction = sb.Stop
答案 1 :(得分:0)
相关帖子 - xaml和code behind
StoryBoard board = (StoryBoard)this.FindResource("OnMouseLeftButtonDown2");
board.stop();