文本更改时启动故事板

发布于 2024-08-08 06:33:25 字数 136 浏览 3 评论 0原文

我有一个 TextBlock 绑定到我的视图模型上的属性。我有一个故事板,使用不透明度属性淡入和淡出文本。我使用此文本在用户执行操作(成功、错误等)后向用户提供反馈。当视图模型的属性发生更改时,如何启动 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稚然 2024-08-15 06:33:25

抱歉,我不想告诉你——但你想错了。

不要考虑故事板、不透明度和可见性属性。
始终思考“视觉状态”。

您刚刚描述的内容(淡入 TextBlock 以响应某些业务逻辑更改)是使用 VisualStateManager 状态的完美案例。

基本上,您最终会得到一个“Is”状态组,该状态组在满足条件(已实现某些状态)时具有一种状态,在不满足条件时具有另一种状态。

强烈建议您花 30 分钟观看这些优秀的 Blend VSM 教程视频。
http://expression.microsoft.com/en-ca/cc643423.aspx
特别是“将状态添加到控件”下的 7 分钟视频。

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< /a>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文