Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference Between RoutedEventHandler and EventHandler

What is the difference between

this.Loaded += new RoutedEventHandler(MainWindow_Loaded);

and

childWindow.MyEvent += new EventHandler(childWindow_MyEvent);
like image 834
MoShe Avatar asked Oct 27 '11 14:10

MoShe


People also ask

What is a RoutedEvent?

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.

Why should we use routed commands instead of events?

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.

What is RoutedEventArgs C#?

RoutedEventArgs(RoutedEvent) Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier. RoutedEventArgs(RoutedEvent, Object)


2 Answers

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.

like image 116
GazTheDestroyer Avatar answered Sep 29 '22 00:09

GazTheDestroyer


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)

like image 34
rockyashkumar Avatar answered Sep 29 '22 00:09

rockyashkumar