WPF交互触发器CallMethodAction

我在给定代码的View部分中使用了事件触发器,如下所示.几乎所有绑定都可以通过ViewModel类-MainWindowViewModel正确地进行,但是对于方法“ CustomRibbonWindow_Loaded”,其抛出的运行时异常如下:

Microsoft.Expression.Interactions.dll中发生类型为’System.ArgumentException’的异常,但未在用户代码中处理
附加信息:在“ MainWindow”类型的对象上找不到与预期签名匹配的名为“ CustomRibbonWindow_Loaded”的方法.
如果有用于此异常的处理程序,则可以安全地继续执行该程序.

我试过把TargetObject =“ {Binding ElementName = RR}”以及TargetObject =“ {Binding}”也放进去.但是似乎没有任何作用.

我在VM中的方法如下

private void CustomRibbonWindow_Loaded()
    {
       ...
    }

请指导如何解决.

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
        <si:CallMethodAction MethodName="CustomRibbonWindow_Loaded"/>
    </i:EventTrigger>

</i:Interaction.Triggers>

MainWindow.xaml

<custom:CustomRibbonWindow x:Class="gDispatchApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
    xmlns:custom="clr-namespace:gDispatchAppLib.Helpers.CustomUIControls;assembly=gDispatchAppLib"
    xmlns:DockUI="clr-namespace:DockingLibrary;assembly=DockingLibrary"
    xmlns:UserControls="clr-namespace:gDispatchAppLib.View.UserControls;assembly=gDispatchAppLib"
    xmlns:AppWindows="clr-namespace:gDispatchAppLib.View.AppWindows;assembly=gDispatchAppLib"
    xmlns:VM="clr-namespace:gDispatchAppLib.ViewModel.AppWindows;assembly=gDispatchAppLib"
    xmlns:VM2="clr-namespace:gDispatchAppLib.ViewModel;assembly=gDispatchAppLib"
    xmlns:PE="clr-namespace:gDispatchAppLib.ViewModel.CADQueues;assembly=gDispatchAppLib"
    xmlns:wpfHelper="clr-namespace:gDispatchAppLib.WPFHelpers;assembly=gDispatchAppLib"   
    xmlns:conv="clr-namespace:gDispatch.MvvmValidation.WPF;assembly=gDispatch.MvvmValidation"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:si="http://schemas.microsoft.com/expression/2010/interactions"

     Title="SERIS CAD"
      MinHeight="300"
                       WindowState="Maximized" HorizontalContentAlignment="Stretch"
    FlowDirection="LeftToRight" CaptionHeight="50"
                 IsIconVisible="False" WindowStyle="SingleBorderWindow"
                       xmlns:my="clr-namespace:System;assembly=mscorlib" 
                       x:Name="RR">
<i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
        <si:CallMethodAction MethodName="CustomRibbonWindow_Loaded" TargetObject="{Binding ElementName=RR}"/>
    </i:EventTrigger>     
</i:Interaction.Triggers>

   ...

</custom:CustomRibbonWindow>

解决方法:

像这样进行方法订阅.

private void Window_Loaded(object sender, RoutedEventArgs e) 
// add the proper parameters
{
    // code here
}  

这里是文档:Link

上一篇:mysql-镜像表:触发器,死锁和隐式提交


下一篇:插入触发器后无法在MySQL中工作