Launch storyboard when text changes

I have a TextBlock binding to a property in my view model. I have a StoryBoard with text change and using Opacity property. I use this text to give feedback to the user after they have completed an operation (success, error, etc.). How do I fire the StoryBoard when a property changes from my view model? Is there a better way to do this kind of effect?

+2


source to share


1 answer


Sorry, I hate to tell you about this, but you are thinking about it the wrong way.

Don't overthink in storyboards, Opacity and Visiblity properties. Always think "visual states".

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



Basically, you will have a group of states "Is", which will have one state when a condition is met (some state is reached), and another - when it is not met.

I highly recommend you spend 30 minutes watching these great Blend VSM videos. http://expression.microsoft.com/en-ca/cc643423.aspx Specifically, a 7 minute video in the Add states to control section .

Erwin van dar walck just posted an excellent article demonstrating how to change VSM states from MVVM, which suits your situation. http://blogs.msdn.com/erwinvandervalk/archive/2009/10/12/how-to-work-with-animations-in-silverlight-in-the-mvvm-pattern.aspx

+4


source







All Articles