Custom events in the Silverlight User Control

Source: Internet
Author: User
Recently, a simple tree structure needs to be made into a user Widget But after the Treeview has been formed, when the user control is called elsewhere, the expected events of the Treeview are gone, such as the unchecked and checked events, in the following Xmal Code Without these events, you can actually implement these events in the user control, but some things cannot be implemented in the user control and can only be implemented by the caller.

< Local: resourcecategorytree X: Name = " Radtreeview1 " > </ Local: resourcecategorytree >

 

After an hour of exploration, I finally got it done. The implementation method is as follows:
1. First declare the required event in the user control, such as the unchecked event, as shown in the following code:

Public   Event Telerik. Windows. radroutedeventhandler unchecked;

 

2. Implement the unchecked that comes with the Treeview in the user control. The Code is as follows:

Private   Void Rtv_unchecked ( Object Sender, telerik. Windows. radroutedeventargs E)

{

//Trigger custom events

If(Unchecked! = Null)

{

Unchecked (sender, e );

}

}

 

3. the unchecked event can be implemented by the caller. It can be implemented in XAML or in background code. The following code is implemented in the background:

Radtreeview1.unchecked + = New Telerik. Windows. radroutedeventhandler (radtreeview1_unchecked );

 

4. The following code is the implementation method.

Private   Void Radtreeview1_unchecked ( Object sender, telerik. windows. radroutedeventargs e)

{

// This event code is ready

}

after the preceding steps, this allows you to implement custom controls in user controls on the caller.
In addition, The Treeview control I use is a third-party control, if you use Microsoft the built-in control of the system changes the namespace and Class.

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.