What is the difference between
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
and
childWindow.MyEvent += new EventHandler(childWindow_MyEvent);
A routed event is an event registered with the WPF event system, backed by an instance of the RoutedEvent class, and processed by the WPF event system. The RoutedEvent instance, obtained from registration, is typically stored as a public static readonly member of the class that registered it.
Routed commands give you three main things on top of normal event handling: Routed command source elements (invokers) can be decoupled from command targets (handlers)—they do not need direct references to one another, as they would if they were linked by an event handler.
RoutedEventArgs(RoutedEvent) Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier. RoutedEventArgs(RoutedEvent, Object)
In short, RoutedEvents are routed. They can bubble up or drill down the visual tree until they hit a handler.
Standard events are just plain direct subscription.
I assume you want to know what's the difference between Events and Routed Events. These 2 articles might help you:
https://msdn.microsoft.com/en-us/library/ms742806(v=vs.100).aspx (a MSDN article)
http://joshsmithonwpf.wordpress.com/2008/03/18/understanding-routed-commands/ (a great article about Routed Commands that also contains a very nice explanation of Routed Events)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With