CoreCLR's Blog

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.



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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: