Silverlight custom cursor

Source: Internet
Author: User
Silverlight custom cursor

In fact, it is very easy to set the cursor to the none value during the load, draw something at the front end, just follow when the mouse moves

< Rectangle Width = "20" Height = "20" X: Name = "Cursor" >
< Rectangle. triggers >
< Eventtrigger Routedevent = "Canvas. Loaded" >
< Beginstoryboard >
< Storyboard >
< Doubleanimation
Storyboard. targetname = "Rotate" Storyboard. targetproperty = "Angle"
By = "360" Duration = "00:00:03" Repeatbehavior = "Forever" />
</ Storyboard >
</ Beginstoryboard >
</ Eventtrigger >
</ Rectangle. triggers >
< Rectangle. rendertransform >
< Rotatetransform X: Name = "Rotate" Centerx = "10" Centery = "10" />
</ Rectangle. rendertransform >
< Rectangle. Fill >
< Lineargradientbrush >
< Gradientstop Color = "White" Offset = "0" />
< Gradientstop Color = "Red" Offset = ". 5" />
< Gradientstop Color = "Black" Offset = "1" />
</ Lineargradientbrush >
</ Rectangle. Fill >
</ Rectangle >

Public   Void Page_loaded ( Object O, eventargs E) {
//Required to initialize Variables
Initializecomponent ();
This. Cursor=Cursors. None;
} Public   Void Onmousemove ( Object Sender, mouseeventargs E) {
Double X = E. getposition ( This ). X;
Double Y = E. getposition ( This ). Y;

If (X <=   20   | X > =   This . Width -   20   | Y <=   20   | Y > =   This . Height -   20 )
This . Cursor. Visibility = Visibility. collapsed;
Else
This . Cursor. Visibility = Visibility. visible;

This . Cursor. setvalue < Double > (Canvas. leftproperty, X );
This . Cursor. setvalue < Double > (Canvas. topproperty, y );
}

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.