开发者

Start Storyboard When Text Changes

开发者 https://www.devze.com 2022-12-08 08:02 出处:网络
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 p

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 S开发者_Python百科toryBoard when the property changes from my view model? Is there a better way to do this sort of effect?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号