Analysis of routed events and traditional events

Source: Internet
Author: User

1:winform

For example, a Button whose onclick method encapsulates a statement that triggers the Click event (or raises the Click event) (such as: if (this). Click!=null) {this.  Click.invoke (s,e);}   The Click event that triggered the button); This is handled by Microsoft: when needed, the OnClick method is invoked to trigger the button's Click event.

2:wpf

For example, a Button whose onclick method encapsulates a statement that triggers the Button.clickevent event (or raises the Button.clickevent event) (such as: Routeeventargs newevent = new Routeeventargs (Button.clickevent,this); This.   RaiseEvent (newevent);}   triggering button.clickevent events); The analysis is handled by Microsoft: when needed, the OnClick method is invoked, triggering the Button.clickevent event (this is a routed event);

For CLR events, it belongs to the instance itself, such as placing a button (button1) in the form layout, and click= "Button1_Click" in the foreground XAML, which is actually the add{this that called the CLR event wrapper.  AddHandler (Clickevent,value); Button1 Install the Button.clickevent event listener} accessor; If you install the Button.clickevent event listener in the Background Code Implementation button button, you need to call this.but in the form where the Button1 button is located Ton1. AddHandler (button.clickevent,new Routedeventhandler (this.button1_click))//button1 install Button.clickevent event listeners. So it concludes that the Button.clickevent event treats the button buttons as equal to the other UIElement controls in the case of installing the Button.clickevent event listener.

3: Is that not all ordinary events need to be routed events? Answer: No, the routed event can only be used in UIElement (because the RaiseEvent method comes from UIElement), the ordinary class can only define "ordinary event", this is not sure????.

4: Is that not all the normal attributes need to be changed to dependency properties?  Answer: No, a dependency property can only be defined in Visual and its subclasses (because the host of the dependency property must be Dependencyobject--uielement:visual:dependencyobject), the normal data entity class can only define "Normal Properties".

Analysis of routed events and traditional events

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.