WPF Attach Event definition

Source: Internet
Author: User
Tags event listener


Routed events are hosted by interface elements that have visual entities, while attached events do not have the ability to display them on the user interface. Two method naming conventions for adding and removing attachment events:

1. The wrapper for adding an additional event listener for the target UI element is aAdd*handlerThe public static method. The asterisk represents the event name, which is the same as the name when registering the event.

2. The wrapper that relieves the UI element from listening on the attached event is the public static method named Remove*handler , and the asterisk is the event name.


The code is as follows:

public class student{Public    int ID {get; set;}    public string Name {get; set;}    public static readonly RoutedEvent namechangedevent = eventmanager.registerroutedevent ("namechanged",         Routingstrategy.bubble,        typeof (Routedeventhandler),        typeof (Student));    public static void Addnamechangedhandler (DependencyObject D, Routedeventhandler h)    {        UIElement element = d as UIE lement;        if (element! = null) element. AddHandler (Student.namechangedevent, h);    }    public static void Removenamechangedhandler (DependencyObject D, Routedeventhandler h)    {        UIElement element = d as UIElement;        if (element! = null) element. RemoveHandler (Student.namechangedevent, h);    }}


WPF Attach Event definition

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.