views:

56

answers:

1

OK I have looked and searched all i want to do is fire a storyboard animation from my view model onto my view. The problem is there is just simply too much boilerplate code to get a simple thing like myStoryboard.Begin(); firing. So what are the methods that you use? Currently, I am using Silverlight 3, MVVM Light.

EDIT: I can't use something like the Visual State Manager since my animations involve keyframes and I don't want to redo them again into states.

A: 

I usually cheat and allow the ViewModel access to the View through an interface. I can then add code-behind for some of the bindings from VM to View that are awkward with pure XAML.

You could also create a DependencyProperty on the View, Bind it to a boolean property on the VM then create a trigger to fire the Animation when the property becomes True. This still requires some boilerplate in the code-behind to define the DP, but at least now the Binding engine is still performing the communication.

Dan Bryant
I agree with Dan's second solution (DependencyProperty on the View). I wouldn't personally want to allow the VM access to the View though...
Surfbutler
I like using the 'IParticularView' pattern for cases where a purely property-driven syntax through binding is awkward. This usually means the VM is wanting to tell the View to 'do something', such as start an animation, pop up a warning box, etc. The View/VM are strongly coupled anyway and abstracting it through an interface still allows stubbing out the View for testing.
Dan Bryant