如何在 MVVM 中的模块/视图之间制作动画?
我有一个 MVVM Silverlight 4 应用程序,它在主窗口的 ViewModel 中保存一个模块列表(一个 UserControl 加上一些元数据)。我在 ContentControl 中显示模块的 UserControl (内容绑定到“CurrentModule.View”)。
我想通过动画视图之间的转换来为应用程序添加一些流行元素。我已经创建了预加载、正常和卸载的视觉状态。当 UserControl 实例化时,我将其状态设置为 PreLoaded。我已将 GoToStateAction 附加到 UserControl 的 Loaded 事件,该事件将状态设置为“正常”,执行一个漂亮的动画以将视图带入视图。效果很好。
如果当用户切换模块时将其动画化到视图之外,我现在需要做什么。我有另一个 GoToStateAction 附加到 UserControl 的“Unloaded”事件,它将状态设置为“Unloaded”。我知道当前的设置不起作用。 ContentControl 一次只能显示一个 UserControl - 一旦发生切换,前一个模块就会消失。我无法确定动画是否在视图上运行,即使它不可见。
我该如何实现我在这里所追求的目标?请记住,我试图以 MVVM 友好的方式做到这一点,尽管我不反对纯粹以演示为中心的一些代码隐藏。
提前致谢! StackOverflow 从来没有让我失望过!
亚当
I have an MVVM Silverlight 4 application that holds a list of modules (a UserControl plus some metadata) in the main window's ViewModel. I am displaying the UserControl of the module in a ContentControl (Content is bound to "CurrentModule.View").
I want to add a bit of pop to the app by annimating the transitions between views. I've created Visual States for PreLoaded, Normal and Unloaded. When the UserControl is instantiated, I set it's state to PreLoaded. I have attached a GoToStateAction to the the Loaded event of the UserControl which sets the state to "Normal", performing a nice animation to bring the View in to view. That works fine.
What I need to do now if animate it out of view when the user switches modules. I have another GoToStateAction attached to the "Unloaded" event of the UserControl which sets the state to "Unloaded". I know that current set up won't work. The ContentControl can only show one UserControl at a time - as soon as the switch happens, the previous module goes away. I can't say for certain if the animation is running on the view even though it's not visiable or not.
How do I accomplish what I'm after here? Please keep in mind that Iam trying to do this in an MVVM-friendly manner, though I'm not opposed to some code-behind when it's purely presentation-focused.
Thanks in advance! StackOverflow has never let me down!
Adam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用 TransitioningContentControl .
它是一个 Silverlight Toolkit 控件,一旦您更改内容,就会有一个漂亮的过渡动画。
Consider using the TransitioningContentControl.
It's a Silverlight Toolkit control that once you change the Content has a nice transition animation.