3
votes

I have Used Event Trigger in my View part given code as below. Almost all bindings are properly with ViewModel class - MainWindowViewModel, but for the method "CustomRibbonWindow_Loaded", its throwing runtime exception like :

An exception of type 'System.ArgumentException' occurred in Microsoft.Expression.Interactions.dll but was not handled in user code Additional information: Could not find method named 'CustomRibbonWindow_Loaded' on object of type 'MainWindow' that matches the expected signature. If there is a handler for this exception, the program may be safely continued.

I have tried putting putting TargetObject="{Binding ElementName=RR}" as well as TargetObject="{Binding}" also. But none of seems working.

My method way in VM is as below,

private void CustomRibbonWindow_Loaded()
    {
       ...
    }

Please guide how to resolve.

<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>
2

2 Answers

3
votes

Do your method subscription like this.

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

Here is the documentation: Link

0
votes

I had the same problem. Just make it public. Thanks for your comment on the other answer :)

public void CustomRibbonWindow_Loaded()