Silverlight learning notes-how to create a custom button control in Silverlight

Source: Internet
Author: User

I. Create a silverlight2 Class Library Project

Start vs2008, select new project, create the silverlight2 class library project, add a control class, and enter the new Project name: mybutton. This class can inherit from the control class or other classes such as contentcontrol and itemcontrol. We inherit from the button,CodeAs 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;

NamespaceMybutton
{
Public ClassMybutton: button
{
}
}

Ii. handling such add events

 

Protected   Override   Void Onmouseleftbuttondown (mousebuttoneventargs E)
{

Base. Onmouseleftbuttondown (E );

E. Handled= False;

}

Protected Override VoidOnmouseleftbuttonup (mousebuttoneventargs E)
{

Base. Onmouseleftbuttonup (E );

E. Handled= False;

}

The complete code 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;

NamespaceMybutton
{
Public ClassMybutton: button
{
Protected Override VoidOnmouseleftbuttondown (mousebuttoneventargs E)
{

Base. Onmouseleftbuttondown (E );

E. Handled= False;

}

Protected Override VoidOnmouseleftbuttonup (mousebuttoneventargs E)
{

Base. Onmouseleftbuttonup (E );

E. Handled= False;

}

}
}

 

3. compile and generate the project. For how to introduce and apply this custom button, see: "silverligth learning notes-how to solve the problem that the button does not respond to the mouseleftbuttondown and mouseleftbuttonup events ".
Go to: Silverlight Study Notes List
This articleProgramIt passes debugging in the silverlight2.0 and vs2008 environments. This article draws on some network materials and hopes to learn from them.
(For more information, see the source)

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.