How to pass an argument of an event as a parameter in an interaction. Run when using MVVM?

Basically, I have an event in my custom class. I will call a specific method in a user class with the argument event → properties as a parameter for this method.

To do this, you can see the actual code for the information.

instance.FileOpening += (sender, e) =>
                {
                    CustomClass.Method(e.XXproperty, e.YYproperty);
                };

But I want to achieve this through interaction. Captures in MVVM. So I used the following code in xaml.

<i:Interaction.Triggers>
     <i:EventTrigger EventName="FileOpening">
          <i:FileOpeningAction TargetObject="{Binding ElementName=cntrol}"/>
     </i:EventTrigger>
</i:Interaction.Triggers>

My corresponding TargetedTriggerAction class is here to force my customclass to execute this method.

public class FileOpeningAction :TargetedTriggerAction<CustomClass>
    {
        protected override void Invoke(object parameter)
        {
            ((instance).TargetObject).Method(?,?);
        }
    }

But my question is: how can I pass e.XXproperty and e.YYproperty in the above action to execute the method in my custom class?

+3
source share
2 answers

, :

<i:EventTrigger EventName="FileOpening">
    <ei:CallMethodAction TargetObject="{Binding}" MethodName="OnFileOpening"/>
</i:EventTrigger>

-

public void OnFileOpening(object sender, EventArgs e){//your code}
+1

, , "PassEventArgsToCommand".

:

xmlns:cmd="xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4""

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseEnter" >
         <cmd:EventToCommand Command="{Binding FooCommand}"
             PassEventArgsToCommand="True" />
    </i:EventTrigger>
</i:Interaction.Triggers>
0

All Articles