0

Storyboard在 XAML 中定义了一个泛型,如下所示:

<Storyboard Core:Key="GenericAnimation" Completed="OnStoryboardCompleted"/>

在我的代码隐藏中如下:

m_GenericAnimation = (Storyboard)Resources["GenericAnimation"];

我的每个Storyboard应用程序都共享相同的Completed事件OnStoryboardCompleted。我想根据刚刚完成的动画来改变我的事件的行为(伪代码):

private void OnStoryboardCompleted(object sender, EventArgs e)
{
    if (completedStoryboard == m_GenericAnimation)
        DoSomethingSpecific();

    DoSomethingCommon();
}

如何Storyboard从发件人那里检索当前完成的内容?如何正确比较两个Storyboard对象?

4

1 回答 1

1

You can use the Name property on Storyboard:

<Storyboard x:Key="Storyboard1" Name="Storyboard1_Name">
    <!-- ... -->
</Storyboard>

<Storyboard x:Key="Storyboard2" Name="Storyboard2_Name">
    <!-- ... -->
</Storyboard>

And then:

Storyboard sb1, sb2;
public MainWindow()
{
    InitializeComponent();
    sb1 = (Storyboard)Resources["Storyboard1"];
    sb2 = (Storyboard)Resources["Storyboard2"];

    sb1.Completed += storyboard_Completed;
    sb2.Completed += storyboard_Completed;
}

void storyboard_Completed(object sender, EventArgs e)
{
    string StoryBoardName = ((ClockGroup)sender).Timeline.Name;
    if (StoryBoardName == "Storyboard1_Name") { /* DoSomething(); */ }
    if (StoryBoardName == "Storyboard2_Name") { /* DoSomething(); */ }
}
于 2013-02-20T16:04:20.233 回答