Rather than use an event generated by an input device, I want to use a custom event that will be raised programatically in the code-behind as an EventTrigger in my xaml.
This should be laughably easy but I can't find an example anywhere.
Here's what I've come up with from studying WPF4 Unleashed Chapter 6, Routed Event Implementation, EventTrigger.RoutedEvent Property, Custom RoutedEvent as EventTrigger, and many others:
MainWindow.xaml.cs:
namespace RoutedEventTrigger
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
RaiseEvent(new RoutedEventArgs(fooEvent, this));
}
public static readonly RoutedEvent fooEvent = EventManager.RegisterRoutedEvent(
"foo", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(MainWindow));
// Provide CLR accessors for the event
public event RoutedEventHandler foo
{
add { AddHandler(fooEvent, value); }
remove { RemoveHandler(fooEvent, value); }
}
}
}
MainWindow.xaml:
P.S. Please be gentle, I am relatively new to WPF.