Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting EventArgs when using interaction triggers

I'm using this way to catch events from XAML:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseWheel">
        <ei:CallMethodAction MethodName="ChangeValue" TargetObject="{Binding DataContext}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

This way works well, I can fire my ChangeValue function in my code. But I would like to know the mouse wheel orientation (up or down) on my ChangeValue function. Is there a way to do that?

like image 336
Ben Avatar asked Jul 22 '26 11:07

Ben


1 Answers

You can use MVVM Light's EventToCommand, which also has a PassEventArgsToCommand property. Then, instead of a method, define a command that receives the event args as a parameter. Your XAML should look something like this:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseWheel">
        <cmd:EventToCommand Command="{Binding ChangeValueCommand}"
                            PassEventArgsToCommand="True" />
    </i:EventTrigger>
</i:Interaction.Triggers>
like image 179
Adi Lester Avatar answered Jul 24 '26 06:07

Adi Lester