How do I call a call method from XAML in WPF?
Except the commands there is another way that allows you to call a method directly from XAML. It is not commonly used but the option is still there.
The method must have one of the two types of signatures
To make it working, you have to include references and namespaces of the Microsoft.Expression.Interactions and System.Windows.Interactivity into your project. Easiest way is to install a nuget. In the example below the namespaces are defined as xmlns:i and xmlns:ei.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
public void VoidParameterlessMethod()
=> Console.WriteLine("VoidParameterlessMethod called");
public void EventHandlerLikeMethod(object o, EventArgs e)
=> Console.WriteLine("EventHandlerLikeMethod called");
}