views:

93

answers:

1

Hello,

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!

+1  A: 

Hi Pavel,

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.

Anvaka