How can I pass the event argument to a command using triggers?

Trident D'Gao picture Trident D'Gao · Nov 26, 2012 · Viewed 19.6k times · Source

So I have a simple setup, an autocompletebox with its Populating event that I want to bind to a command. I use

clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity 

(is there a better namespace for doing this?)

It's not a big deal to bind it, the big deal is to pass that PopulatingEventArgs argument to the bound command.

So how do I do it according to the best practices of PRISM in particular and MVVM in general?

Answer

Sean Chase picture Sean Chase · Aug 16, 2013

I tried the InteractiveCommand and it caused problems for me. Instead I set a reference to Microsoft.Expression.Interactions and included

xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 

<i:Interaction.Triggers>
    <i:EventTrigger EventName="AppointmentEditing">
        <ei:CallMethodAction MethodName="AppointmentEditing" TargetObject="{Binding}" />
    </i:EventTrigger>
    <i:EventTrigger EventName="ShowDialog">
        <ei:CallMethodAction MethodName="ShowDialog" TargetObject="{Binding}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

...in my UserControl.

Then put the event handlers in my ViewModel and set the scope to public:

public void ShowDialog(object sender, ShowDialogEventArgs e) {

}

public void AppointmentEditing(object sender, AppointmentEditingEventArgs e) {

} 

Working well so far.