views:

466

answers:

2

I have a couple of Storyboards in my view that I would like to trigger from the ViewModel if possible. Is there a simple way or elegant way of doing this. Here is what I am trying to do.

Person Clicks on a Button-->RelayCommand (In the ViewModel), the Relay Command should then play the storyboard. Also one more thing, I would like to also trigger the storyboard animation by itself in the ViewModel without any interaction.

    <i:Interaction.Triggers>
 <i:EventTrigger EventName="MouseLeftButtonDown">
    <cmd:EventToCommand Command="{Binding ButtonPress}"                                                     CommandParameterValue="RedButtonLight">
    </cmd:EventToCommand>
         </i:EventTrigger>
          </i:Interaction.Triggers> 
+1  A: 

If the button click is purely to power a view-related thing and isn't doing any actual application logic, then I would argue that you can do all this in the code-behind of the view class.

If this isn't the case then I would use a property on the Presentation (ViewModel) to signal that the Presentation is in a state, and have the view react to the PropertyChanged event and start the storyboard. This is assuming you are implimenting INotifyPropertyChanged on your Presentation class.

Jason Jackson
+1  A: 

Have a look at the expression samples. There is a trigger for events from the datacontext. DataEventTrigger

You could use that to trigger a ControlStoryboardAction to start the story board whenever your viewmodel raises a particular event.

Your viewmodel could then raise the event as part of the command as well as at other times.

Graeme Bradbury