Learning WPF-Understanding routing events and wpf routing events
Getting startedLet's look at an example.
Front-end code: Background code: click the button to run the code The first pop-up window The second pop-up window: The third pop-up window: Description
When the Button is clicked, The click Event of the Button is triggered first and then searched. It is found that stackpanel has registered the event, and then the Button of StackPanel is triggered. click Event, and then trigger the Grid Button. click Event, which is the most basic event routing. |
If you do not want to register a routing event in XAML, you can also register a routing event by encoding as follows, you can use this method. The above example is a bubble routing event, which is an internal and external event. In WPF, another event is a tunnel routing event, which is an event transmitted from the external |
Route event Parsing In the preceding example, we can see the routing event Click of the Button class. Next we will analyze the source code to see how the Button registers this routing event.
To use a routing event, you must first define a routing event. First, you can use EventManager in the ClickEvent code of the Button class's base class ButtonBase. registerRoutedEvent registers a route event. This method contains the event name, route type, and other content. |
After a ClickEvent event is defined, the event needs to be encapsulated. The. Net event package is used here, AddHandler and RemoveHandler are used to add and delete registered calling programs. |
Modify record: Completed part of content: completed all contentReferencesPro WPF 4.5 in C # 4th Edition http://www.cnblogs.com/DebugLZQ/archive/2012/12/03/2799314.html |
|