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 [2012/11/05 18:04] smayr [Example of Custom RoutedEvent] |
swdev:dotnet:events [2015/06/15 15:28] (current) ajdavis [Routed Events] |
||
---|---|---|---|
Line 164: | Line 164: | ||
== Routed Events == | == Routed Events == | ||
- | In WPF, you also have access to Routed Events, which have additional advantages. | + | In WPF, you also have access to Routed Events, which have additional advantages. |
RoutedEvents are particularly useful if the listener doesn' | RoutedEvents are particularly useful if the listener doesn' | ||
Line 174: | Line 174: | ||
Writing a custom routed event is similar to writing a dependency property, | Writing a custom routed event is similar to writing a dependency property, | ||
<code csharp> | <code csharp> | ||
- | public static readonly RoutedEvent | + | public static readonly RoutedEvent |
- | " | + | " |
| | ||
| | ||
Line 181: | Line 181: | ||
// Provide CLR property wrapper for the routed event | // Provide CLR property wrapper for the routed event | ||
- | public event RoutedEventHandler | + | public event RoutedEventHandler |
{ | { | ||
- | add { AddHandler(MyRoutedEvent, value); } | + | add { AddHandler(OnMyActionEvent |
- | remove { RemoveHandler(MyRoutedEvent, value); } | + | remove { RemoveHandler(OnMyActionEvent |
} | } | ||
// Method to raise event | // Method to raise event | ||
- | public void RaiseMyRoutedEvent() | + | public void RaiseMyActionEvent() |
{ | { | ||
- | | + | |
} | } | ||
Line 310: | Line 310: | ||
// Attach menu event handler | // Attach menu event handler | ||
- | popupmnu1.MenuItemSelected += new RoutedEventHandler(ucPopupMnu_MenuItemSelected); | + | |
+ | // or | ||
+ | AddHandler(ucPopupMnu.MenuItemSelectedEvent, | ||
} | } | ||