MVVM- Trigger Storyboard in the View Model in Silverlight

元气小坏坏 提交于 2019-12-05 21:59:24

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/

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!