具有 MVVM 模式的动画
使用 MVVM 模式时触发动画的最佳方式是什么?更具体地说,我有一个包含多个字段的表单。当用户单击保存按钮时,我想显示一个动画。我已经能够通过公开属性 ShowMessage 并将其设置为 True 并且 DataTrigger
获取该值并启动动画来实现此目的。但是,当动画仍然处于活动状态时,我想将表单重置为干净的状态。到目前为止,我已经通过订阅 Storyboard
上的 Complete
事件并重置该事件上的视图模型状态来完成重置。
理想情况下,我希望能够以某种方式从视图模型触发动画(因为保存将是异步操作)并让动画运行完成。我现在的方式不起作用,因为一旦我更改了 ShowMessage 属性的值(在重置时),动画就会停止并且不会运行完成。
有人有更好的解决方案吗?
谢谢!
What is the best way to trigger an animation while using the MVVM pattern? More specifically, I have a form which has several fields. When a user click's the save Button
, I would like to show an animation. I have been able to achieve this by exposing a property ShowMessage and setting it to True and a DataTrigger
picks up this value and starts an animation. However, while the animation is still active, I would like to reset the form to a clean state. So far I've done the reset by subscribing to the Complete
event on the Storyboard
and resetting the view model's state on that event.
Ideally I would like to be able to somehow trigger an animation from the view model (because the save would be an asynchronous operation) and let the animation run to completion. The way I have it now wouldn't work because once I change the value of the ShowMessage property (on the reset), the animation stops and doesn't run to completion.
Does any one have a better solution?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想到了两个选择。第一个是VSM,第二个是依附行为。您可能会发现 Marlon Grech 的以下帖子很有用:动画和 MVVM< /a>.
希望这有帮助。
Two options comes into my mind. The first is VSM, and the second is attached behaviors. You may find useful the following post from Marlon Grech: Animations and MVVM.
Hope this helps.