Differences
This shows you the differences between two versions of the page.
Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
swdev:dotnet:events [2013/01/25 12:35] smayr |
swdev:dotnet:events [2015/06/15 15:28] (current) ajdavis [Routed Events] |
== Routed Events == | == Routed Events == |
| |
In WPF, you also have access to Routed Events, which have additional advantages. Events can "tunnel" or "bubble" to other components in the visual tree. | In WPF, you also have access to Routed Events, which have additional advantages. Events can "tunnel down" or "bubble up" to other components in the visual tree. |
| |
RoutedEvents are particularly useful if the listener doesn't have a direct reference to the source of the event. For example you have a container control which must react to a specific event, but the container will not always know exactly which controls inside it can/will throw it. The controls can be several levels deep, or created by a template. – Source: [[http://stackoverflow.com/questions/2536950/c-wpf-routedevent-in-wpf-class-that-isnt-a-uielement|Bubblewrap@Stackoverflow.com]] | RoutedEvents are particularly useful if the listener doesn't have a direct reference to the source of the event. For example you have a container control which must react to a specific event, but the container will not always know exactly which controls inside it can/will throw it. The controls can be several levels deep, or created by a template. – Source: [[http://stackoverflow.com/questions/2536950/c-wpf-routedevent-in-wpf-class-that-isnt-a-uielement|Bubblewrap@Stackoverflow.com]] |
| |
// Attach menu event handler | // Attach menu event handler |
popupmnu1.MenuItemSelected += new RoutedEventHandler(ucPopupMnu_MenuItemSelected); | //popupmnu1.MenuItemSelected += new RoutedEventHandler(ucPopupMnu_MenuItemSelected); |
| // or |
| AddHandler(ucPopupMnu.MenuItemSelectedEvent, new RoutedEventHandler(ucPopupMnu_MenuItemSelected)); |
} | } |
| |