MVVM-在Silverlight视图模型中触发故事板

发布于 2024-08-26 19:02:45 字数 571 浏览 5 评论 0原文

我认为如果可能的话,我想从 ViewModel 触发几个故事板。有没有一种简单的方法或优雅的方法来做到这一点。这就是我正在尝试做的事情。

人员单击按钮 --> RelayCommand(在 ViewModel 中),然后 Relay Command 应该播放情节提要。另外一件事,我还想在 ViewModel 中自行触发故事板动画,而无需任何交互。

    <i:Interaction.Triggers>
 <i:EventTrigger EventName="MouseLeftButtonDown">
    <cmd:EventToCommand Command="{Binding ButtonPress}"                                                     CommandParameterValue="RedButtonLight">
    </cmd:EventToCommand>
         </i:EventTrigger>
          </i:Interaction.Triggers> 

I have a couple of Storyboards in my view that I would like to trigger from the ViewModel if possible. Is there a simple way or elegant way of doing this. Here is what I am trying to do.

Person Clicks on a Button-->RelayCommand (In the ViewModel), the Relay Command should then play the storyboard. Also one more thing, I would like to also trigger the storyboard animation by itself in the ViewModel without any interaction.

    <i:Interaction.Triggers>
 <i:EventTrigger EventName="MouseLeftButtonDown">
    <cmd:EventToCommand Command="{Binding ButtonPress}"                                                     CommandParameterValue="RedButtonLight">
    </cmd:EventToCommand>
         </i:EventTrigger>
          </i:Interaction.Triggers> 

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

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

发布评论

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

评论(4

并安 2024-09-02 19:02:45

我知道那是很久以前的事了。但我已经写了一篇关于触发故事板和 MVVM 的详细博客文章。

http://mark.mymonster.nl/ 2010/12/14/trigger-a-storyboard-on-viewmodel-changes/

I know it's a long time ago. But I've written a detailed blog post about Triggering Storyboards and MVVM.

http://mark.mymonster.nl/2010/12/14/trigger-a-storyboard-on-viewmodel-changes/

淡淡的优雅 2024-09-02 19:02:45

如果按钮单击纯粹是为了启动与视图相关的操作,并且没有执行任何实际的应用程序逻辑,那么我认为您可以在视图类的代码隐藏中完成所有这些操作。

如果不是这种情况,那么我将使用演示文稿 (ViewModel) 上的属性来表示演示文稿处于某种状态,并使视图对 PropertyChanged 事件做出反应并启动情节提要。这是假设您正在演示文稿类上实现 INotifyPropertyChanged。

If the button click is purely to power a view-related thing and isn't doing any actual application logic, then I would argue that you can do all this in the code-behind of the view class.

If this isn't the case then I would use a property on the Presentation (ViewModel) to signal that the Presentation is in a state, and have the view react to the PropertyChanged event and start the storyboard. This is assuming you are implimenting INotifyPropertyChanged on your Presentation class.

拿命拼未来 2024-09-02 19:02:45

查看表达式示例。数据上下文中的事件有一个触发器。 DataEventTrigger

每当您的视图模型引发特定事件时,您可以使用它来触发 ControlStoryboardAction 来启动故事板。

然后,您的视图模型可以将事件作为命令的一部分以及在其他时间引发。

Have a look at the expression samples. There is a trigger for events from the datacontext. DataEventTrigger

You could use that to trigger a ControlStoryboardAction to start the story board whenever your viewmodel raises a particular event.

Your viewmodel could then raise the event as part of the command as well as at other times.

旧梦荧光笔 2024-09-02 19:02:45

下面介绍了如何在 Blend 中执行此操作,而无需触及一行 xaml 或代码:
http://www.basarat.com/2011/05/expression -blend-starting-storyboard.html

Heres how you can do it in blend without touching a line of xaml or code :
http://www.basarat.com/2011/05/expression-blend-starting-storyboard.html

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