Implementation of the Button in Silverlight1.0

Source: Internet
Author: User

As we all know, there is no button class in silverlight1.0. To implement the button effect, mouseenter, mouseleave, mouseleftdown, mouseleftup, three image images are required: img_name, img_click, and img_over to indicate the button status.
Mouse event correspondence:
Mouseenter corresponds to img_over; mouseleave corresponds to img_name; mouseleftdown corresponds to img_click; mouseleftup corresponds to img_over;
The three images need to be placed in a canvas class. The most important thing is to make the three images istesthit = false, while the istesthit = true of the canvas.
#01 ffffff of the background of the most important canvas (the background color must be set; otherwise, the click event cannot be triggered)

Instance code:
XAML code

<Canvas. Left = "0" Canvas. Top = "64"
Width = "39" Height =" 360"
X: Name = "Pre" IsHitTestVisible = "True"
Background = "#01 FFFFFF">
<Image Source = "SilverlightImg/PrevArrow.png"
X: Name = "Img_Pre"
Width = "36" Height =" 358"
Canvas. Top = "5" Canvas. Left = "-5"
IsHitTestVisible = "False"/>
<Image IsHitTestVisible = "False"
Width = "36" Height =" 358"
Source = "SilverlightImg/PrevArrow_Over.png"
Stretch = "Fill" Canvas. Left = "-5" Canvas. Top = "5"
X: Name = "Img_Pre_Over" Visibility = "Collapsed"/>
<Image IsHitTestVisible = "False"
Width = "36" Height =" 358"
Canvas. Top = "5" Source = "silverlightimg/prevarrow_click.png"
Stretch = "fill" X: Name = "img_pre_click"
Canvas. Left = "-8" visibility = "Collapsed"/>
</Canvas>

Bind event:

This. Next. addeventlistener ("mouseenter", handleprenextmouseenter );
This. Next. addeventlistener ("mouseleftbuttondown", handleprenextmousedown );
This. Next. addeventlistener ("mouseleftbuttonup", handleprenextmouseup );
This. Next. addeventlistener ("mouseleave", handleprenextmouseleave );

Event handling code:

Function handlePreNextMouseDown (sender, eventArgs)
{
Var imgName = "Img _" + sender. Name + "_ Click"
Var imgButton = sender. findName (imgName );
ImgButton. visibility = "Visible ";
ImgName = "Img _" + sender. Name + "_ Over ";
ImgButton = sender. findName (imgName );
ImgButton. visibility = "Collapsed ";
}

Function handleprenextmouseup (sender, eventargs)
{
VaR imgname = "IMG _" + sender. Name + "_ click"
VaR imgbutton = sender. findname (imgname );
Imgbutton. Visibility = "Collapsed ";
Imgname = "IMG _" + sender. Name + "_ over ";
Imgbutton = sender. findname (imgname );
Imgbutton. Visibility = "visible ";
}

Function handlePreNextMouseLeave (sender, eventArgs)
{
HandleMouseLeave (sender, eventArgs );
Var imgName = "Img _" + sender. Name + "_ Click ";
Var imgButton = sender. findName (imgName );

If (imgButton! = Null)
{
ImgButton. visibility = "Collapsed ";
}
}

Function handleMouseEnter (sender, eventArgs)
{
Var imgName = "Img _" + sender. Name + "_ Over ";
Var imgButton = sender. findName (imgName );
ImgButton. visibility = "Visible ";

ImgName = "Img _" + sender. Name;
ImgButton = sender. findName (imgName );
ImgButton. visibility = "Collapsed ";
}

Function handleMouseLeave (sender, eventArgs)
{
Var imgName = "Img _" + sender. Name + "_ Over ";
Var imgButton = sender. findName (imgName );
ImgButton. visibility = "Collapsed ";

ImgName = "Img _" + sender. Name;
ImgButton = sender. findName (imgName );
ImgButton. visibility = "Visible ";
}

This is a small experience summarized in Silverlight development. Let's record it here

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.