Silverlight learning notes-create a Silverlight custom control (3)-operation control internal Member

Source: Internet
Author: User
In the above custom control mysilverbutton, we have two internal members: rectangle (bodyelement) and textblock (buttoncaption). To operate on them, we need to use the gettemplatechild function to achieve our goal.
Here, we modify the text attribute value of textblock. Join Code To the simplebutton_mouseleftbuttonup event Void Simplebutton_mouseleftbuttonup ( Object Sender, mousebuttoneventargs E)
{
If (Click ! =   Null )
{
Click ( This , New Routedeventargs ());
Textblock bgtextblock = (Sender As Mysilverbutton ).( " Buttoncaption " ) As Textblock;
Bgtextblock. Text =   " Modify display text " ;
}
}

The complete code of mysilverbutton. CS is as follows: Using System;
Using System. net;
Using System. windows;
Using System. Windows. controls;
Using System. Windows. documents;
Using System. Windows. Ink;
Using System. Windows. input;
Using System. Windows. Media;
Using System. Windows. Media. animation;
Using System. Windows. shapes;

Namespace Mydesignbutton
{
Public   Class Mysilverbutton: contentcontrol
{
Public   Event Routedeventhandler click; // Add a click event

Public Mysilverbutton ()
{
This . Defaultstylekey =   Typeof (Mysilverbutton );

This. Mouseleftbuttonup+ = NewMousebuttoneventhandler (simplebutton_mouseleftbuttonup );//Add a click event

}

// Add a click event
Void Simplebutton_mouseleftbuttonup ( Object Sender, mousebuttoneventargs E)
{
If (Click ! =   Null )
{
Click ( This , New Routedeventargs ());
Textblock bgtextblock = (Sender As Mysilverbutton ).( " Buttoncaption " ) As Textblock;
Bgtextblock. Text =   " Modify display text " ;
}
}

}
}

Re-Generate and return to the myslbutton project to run the test. You can see the result.

Next article:
Silverlight learning notes -- create a Silverlight custom control (4) -- add custom attributes

Go to: Silverlight Study Notes List

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.