Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a event argument as a parameter in interaction.Trigger when using MVVM?

Tags:

mvvm

wpf

Basically i have an Event in my custom class. I will call the particular method in the custom class with the event's argument -> properties as a parameter for that method.

You can observe the actual code behind information for this.

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

But i want to achieve this through interaction.Triggers 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 get my customclass to execute the method.

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

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

like image 307
David Bekham Avatar asked Feb 02 '26 06:02

David Bekham


1 Answers

You can try to use also interactivity library, then you can write this :

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

And in you code it will be something like

public void OnFileOpening(object sender, EventArgs e){//your code}
like image 176
Sasha Avatar answered Feb 04 '26 01:02

Sasha