Using the Visual State Manager to trigger animations in WP7

May 4, 2011 at 5:25 PM

I've been trying to figure out how to employ the Visual State Manager in WP7 to start/stop animations from the viewmodel, but I'm not quite sure where to start. The one blog post I found on the subject made it sound like you would inject the VSM into the viewmodel, then use it to get a reference to the control and start the animation.

This seems like it would cause coupling between your VM and view-specific code. Is this the recommended way to use the VSM?

Also, is there a Caliburn.Micro wrapper or handle for the VSM? I'm not sure how I would go about injecting it. I'm using SimpleContainer.

May 4, 2011 at 5:30 PM

You definitely do not want to inject the VSM into your VM. There's nothing specifically in Caliburn.Micro for this. Usually, you can accomplish it with an attached property, bound to your VM, which calls the VSM when the property changes. I know I've seen some blogs on this or someone has posted their solution in the forums before.

May 4, 2011 at 5:34 PM

Ah, I get it. So you're sort of mimicking the functionality of a DataTrigger, in that the VSM watches a viewmodel property and independently goes into action when the property changes. Correct?

If so, that makes a lot more sense and avoids the coupling issue. Perfect. I'll see if I can track down those blog posts; maybe they were Silverlight posts, since I was looking for WP7 specific stuff.

May 4, 2011 at 5:53 PM

Yeah, that's basically the idea. Definitely look for Silverlight posts.

May 12, 2011 at 10:11 PM

The way I've approached this is created an attached dependency property on the view which is bound to the view model in some way (usually a State property). This works fairly well, makes the view model state changes fairly testable.