Using interaction triggers in MVVM
Posted by coreclr on January 5, 2011
Commands are ofter to limited when using the MVVM pattern. Instead we can use interaction triggers.
Here is a simple example of handling the MouseEnter event for a button in a viewModel.
XAML:
ViewModel:
The key point here is the CallMethodAction object. CallMethodAction is a TriggerAction defined in the Microsoft.Expression.Interactivity.Core namespace. In this example I set TargetObject to the DataContext (the viewModel) and MethodName to the method we want to call in the ViewModel.
If you need to send parameters to the method, you just expose those as properties in the viewModel and use standard DataBinding.
Remember to reference Microsoft.Expression.Interactions.dll
Leave a Reply