views:

247

answers:

2

I'm writing a MVVM app and have started putting in a few animations. I want to call something on the ViewModel which starts the a storyboard. This blog had a promising approach to it, but it doesn't actually work. The IDChanged handler never fires for some reason.

I also found that you could start animations on EventTriggers, but I don't know how to raise one on the ViewModel.

+1  A: 

I have a property in my VM that reflects the state of the application. The elements in the view that are animated have a data trigger that starts a storyboard when the VM property has a certain value.

Carlos
I know how to do that. You set up a trigger to start the storyboard when you enter a condition. But I just need to do a one-off animation: I want to do a quick, temporary flash on a UI element to bring attention to it.
RandomEngy
I haven't considered generalizing this, so I don't know if this helps you. I once had a similar need. I had to 'flash' a button if there was no activity for a minute. I did this by having a storyboard attached to the button, the storyboard would do nothing for a minute then do the flash. In my case, the button went away when clicked so it made the scenario simpler. A flash on a UI element to grab attention sounds like view related only. Is there a way the view can determine when to to the flash by itself? Why would the VM care about flashing a UI element? Sorry, this may not be much help.
Carlos
Well, several commands that fire on one window would trigger this flash in another window. My windowing model is set up such that the VM knows about the relationships between the windows, but the views do not.
RandomEngy
Do you have some sample code on this DataTrigger? I tried that and it didn't really work out with my DataBindings
Tigraine
A: 

I ended up adding an AnimationStarted event to my ViewModel with a key string for what animation it is. Then on the view I create the animation programmatically, subscribe to the AnimationStarted event, and kick the appropriate animation off when it fires.

RandomEngy