Learning WPF-Understanding routing events and wpf routing events

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.