Reputation: 2175
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 ?
Upvotes: 3
Views: 3962
Reputation: 418
If you follow as given below, then you can pass the event arguments to the command by setting the "PassEventArgsToCommand".
add the reference :
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>
Upvotes: 0
Reputation: 853
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}
Upvotes: 1