0

I have a generic Storyboard defined in my XAML as follows:

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

And in my code-behind as follows:

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

Every Storyboard of my applications shares the same Completed event OnStoryboardCompleted. I would like to change a little bit the behavior of my event depending on the animation that is just being completed like so (pseudocode):

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

How can I retrieve the currently completed Storyboard from sender? How can I correctly compare two Storyboard objects?

1 Answer 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(); */ } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.