Silverlight: Starting a storyboard within another storyboard
I've been banging my head against concrete walls for sometime, trying to find out how to start a storyboard within another storyboard.
For the silverlight/WPF experienced, this might be a small task. For beginners, it is a daunting task, unless you already know how to do it.
Here's how I did it...
1. I had to create a dependency property. (why? because DPs are awesome and I love them, and then they are the only properties that can be affected by animations.
2. My problem statement. If yours is similar, you might benefit:
- I have a user control (uc1) that has a rectangle on it (red in color).
- I create a storyboard (sbRedToBlue) on the user control (uc1) that changes the red to blue over 2 seconds (or whatever your animation is)
- Now I create another user control (uc2) and host an instance of the first control (uc1).
- I create another storyboard (sbDoTheThing) in the uc2 and want to run uc1.sbRedToBlue when sbDoTheThing reaches 00:00:500.
3. My Solution:
- I create a dependency property Boolean ReadyToRoll in uc1.
- We have some bad news now, if you're using silverlight we've small glitch that prevents changes from being reflected in the UI. The good news, however, is that there is a workaround. Use callbacks. (http://stackoverflow.com/questions/3870266/storyboard-changing-property-but-not-reflected-in-ui)
- In the callback, I check for the new value of the dp, if it is true (which means ReadyToRoll is true), I begin uc1.sbRedToBlue.
- Its gets all the simple now, In expression blend when I am editing uc2.sbDoTheThing, at 00:00:500, I select instance of uc2, open up the misc panel in the property explorer, and there I see the property ReadyToRoll. I set this to true... My prayers are heard.
I've written this post while being pushed for timelessness. Feel free to write to me on my email address g.sarwal@gmail.com for further support/help/recommendations/suggestions/blah-blah/rant...
Comments
Spent timeless hours figuring how to run one SB from another. Seeing how it could be simply done using a DP on the control from the StoryBoard itself, is just amazing, thanks a lot.
Should post this on the Microsoft site.