3

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

您可以观察信息背后的实际代码。

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

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

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

我相应的 TargetedTriggerAction 类在这里是为了让我的 customclass 执行该方法。

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

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

4

2 回答 2

1

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

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

在您的代码中,它将类似于

public void OnFileOpening(object sender, EventArgs e){//your code}
于 2013-06-07T13:49:51.367 回答
0

如果您按照下面给出的方式进行操作,则可以通过设置“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>
于 2014-12-17T10:26:31.687 回答