Windows Phone 7 rotation animation (rotatetransform)

Source: Internet
Author: User

The so-called rotatetransform is an element that rotates with a coordinate point as the center point. When using the rotatetransform, you must pay attention to two points: the center) and angle ).

In this example, we set a rotation based on angle changes and a rotation based on time changes.

    <  Grid  X: Name  = "Contentpanel"  Grid. Row  = "1"  Margin  = "12, 0, 12, 0"  >  
< Grid. rowdefinitions >
< Rowdefinition Height = "*" />
< Rowdefinition Height = "*" />
< Rowdefinition Height = "Auto" />
</ Grid. rowdefinitions >

< Textblock Grid. Row = "0"
Text = "Frame-based"
Fontsize =" {Staticresource phonefontsizelarge} "
Horizontalalignment = "Center"
Verticalalignment = "Center"
Rendertransformorigin = "0.5 0.5" >
< Textblock. rendertransform >
< Rotatetransform X: Name = "Rotate1" />
</ Textblock. rendertransform >
</ Textblock >

< Textblock Grid. Row = "1"
Text = "Time-based"
Fontsize =" {Staticresource phonefontsizelarge} "
Horizontalalignment = "Center"
Verticalalignment = "Center"
Rendertransformorigin = "0.5 0.5" >
< Textblock. rendertransform >
< Rotatetransform X: Name = "Rotate2" />
</ Textblock. rendertransform >
</ Textblock >

< Button Grid. Row = "2"
Content = "Pause for 5 seconds"
Horizontalalignment = "Center"
Click = "Onbuttonclick" />
</ Grid >
 Using  System;
Using System. Threading;
Using System. windows;
Using System. Windows. Media;
Using Microsoft. Phone. controls;

Namespace Framebasedvstimebased
{
Public Partial Class Mainpage: phoneapplicationpage
{
Datetime starttime;

Public Mainpage ()
{
Initializecomponent ();

Starttime = Datetime. now;
Compositiontarget. Rendering + = Oncompositiontargetrendering;
// When this event occurs, there is a visual framework that can be used to render the Silverlight content graph.
// Then, you can processProgramModifies the visual object of an application or any other content at a frame.
}

Void Oncompositiontargetrendering ( Object Sender, eventargs ARGs)
{
// Frame-based
Rotate1.angle = (Rotate1.angle + 0.2 ) % 360 ; // Set clockwise rotation angle

// Time-based
Timespan elapsedtime = Datetime. Now - Starttime;
Rotate2.angle = (Elapsedtime. totalminutes * 360 ) % 360 ;
}
// Pause for 5 seconds
Void Onbuttonclick ( Object Sender, routedeventargs ARGs)
{
Thread. Sleep ( 5000 );
}
}
}
Related Article

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.