silverlightsilverlight-3.0silverlight-2.0

Start Storyboard When Text Changes


I have a TextBlock bound to a property on my view model. I have a StoryBoard with fades the text in and out using the Opacity property. I am using this text to give the user feedback after they have performed an operation(success, error etc). How can I start the StoryBoard when the property changes from my view model? Is there a better way to do this sort of effect?


Solution

  • Sorry, I hate to tell it to you - but you're thinking about it wrong.

    Don't think in storyboards, Opacity and Visiblity properties. Always think "Visual States".

    What you just described (fading in a TextBlock in response to some business logic change) is a perfect case for using VisualStateManager states.

    Basically you'll end up having a "Is" state group that'll have one state for when the condition is met (some state has been achieved) and another for when it's not met.

    I strongly suggest you spend 30 minutes watching these excellent Blend VSM tutorial videos. http://expression.microsoft.com/en-ca/cc643423.aspx Specifically the 7 minutes video under "Add States to a Control".

    Erwin van dar valk just published an excellent article demoing how to change VSM states from MVVM that's Pertinent to your situation. http://blogs.msdn.com/erwinvandervalk/archive/2009/10/12/how-to-work-with-animations-in-silverlight-in-the-mvvm-pattern.aspx