Silverlight4 learning notes-square mouse follow

Source: Internet
Author: User

XAMLCode:
========================================================== =====

 

<Usercontrol X: class = "test_sl.mainpage"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: D = "http://schemas.microsoft.com/expression/blend/2008"
Xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006"
MC: ignorable = "D"
D: designheight = "300" D: designwidth = "400">

<Grid X: Name = "LR" background = "blue">
<Stackpanel horizontalalignment = "Left"> </stackpanel>
<Rectangle Height = "50" horizontalalignment = "Left" name = "rectangle1" stroke = "{X: null} "strokethickness =" 1 "verticalalignment =" TOP "width =" 50 "fill =" red "margin =" 10, 10, 0, 0 "radiusx =" 5 "radiusy =" 5 ">
<Rectangle. rendertransform>
<Translatetransform X: Name = "TT" x = "0" Y = "0"/>
</Rectangle. rendertransform>
</Rectangle>
</GRID>
</Usercontrol>

 

CS code:

========================================================== =====

 

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. net;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. shapes;

Namespace test_sl
{
Public partial class mainpage: usercontrol
{
Public mainpage ()
{
Initializecomponent ();
This. myinit ();
}

Private void myinit ()
{
This. LR. mouseleftbuttondown + = new mousebuttoneventhandler (lr_mouseleftbuttondown );
}

Void lr_mouseleftbuttondown (Object sender, mousebuttoneventargs E)
{
Storyboard sb = new storyboard ();
// Obtain the current mouse position.
Point P = E. getposition (this. lr );

// horizontal motion animation.
doubleanimation Dax = new doubleanimation ()
{< br> to = P. x,
duration = timespan. frommilliseconds (500)
};
storyboard. settargetproperty (Dax, new propertypath ("X");
storyboard. settarget (Dax, this. TT);
Sb. children. add (Dax);

// an animation of vertical motion.
doubleanimation day = new doubleanimation ()
{< br> to = P. y,
duration = timespan. frommilliseconds (100)
};
storyboard. settargetproperty (day, new propertypath ("Y");
storyboard. settarget (day, this. TT);
Sb. children. add (day);

// Start the animation.
SB. Begin ();
}
}
}

 

It seems quite simple.

 

 

 

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.