使用MVVM时如何在interaction.Trigger中将事件参数作为参数传递? [英] How to pass a event argument as a parameter in interaction.Trigger when using MVVM?

查看:131
本文介绍了使用MVVM时如何在interaction.Trigger中将事件参数作为参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我的自定义类中有一个事件.我将使用事件的参数 -> 属性作为该方法的参数调用自定义类中的特定方法.

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);
                };

但我想通过 MVVM 中的交互来实现这一点.所以我在 xaml 中使用了以下代码.

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>

我对应的 TargetedTriggerAction 类在这里是为了让我的自定义类来执行该方法.

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(?,?);
        }
    }

但我的问题是如何通过上述操作中的 e.XXproperty 和 e.YYproperty 来执行我的自定义类中的方法?

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 ?

推荐答案

你也可以尝试使用交互库,然后你可以这样写:

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>

在你的代码中它会像

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

这篇关于使用MVVM时如何在interaction.Trigger中将事件参数作为参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆