文本更改时启动情节提要 [英] Start Storyboard When Text Changes
问题描述
我有一个TextBlock绑定到我的视图模型上的一个属性.我有一个StoryBoard,使用Opacity属性可以淡入和淡出文本.我正在使用此文本为用户执行操作(成功,错误等)后提供反馈.当属性从视图模型更改时,如何启动StoryBoard?有没有更好的方法来实现这种效果?
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?
推荐答案
对不起,我不想告诉您-但您认为它有误.
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".
您刚刚描述的内容(响应某些业务逻辑更改而在TextBlock中退色)是使用VisualStateManager状态的完美案例.
What you just described (fading in a TextBlock in response to some business logic change) is a perfect case for using VisualStateManager states.
基本上,您最终将拥有一个"Is"状态组,该组在满足条件(已达到某些状态)时具有一个状态,而在不满足该条件时具有另一个状态.
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.
我强烈建议您花30分钟观看这些出色的Blend VSM教程视频. http://expression.microsoft.com/en-ca/cc643423.aspx 尤其是"将状态添加到控件下的7分钟视频.
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刚刚发表了一篇很棒的文章,演示了如何从MVVM中更改与您的情况有关的VSM状态. http://blogs.msdn.com/erwinvandervalk/archive/2009/10/12/how-to-work-with-animations-in-silverlight-in-the-mvvm-pattern.aspx
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
这篇关于文本更改时启动情节提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!