Windows Phone development and learning-rotation animation during loading

Source: Internet
Author: User

During Windows Phone development, sometimes we use progressbar to indicateProgramLoading is in progress, but you can also design a rotating image (similar to the 360 anti-virus software) to indicate loading is in progress. As shown below:

The following describes the implementation process:

Step 1: Add a rotating PNG image to the Project

Step 2: Add the following animation effects to mainpage and XAML.

 
<Phone: phoneapplicationpage. resources> <storyboard X: Name = "spinninganimation"> <doubleanimation autoreverse = "false" Duration = "0: 0" from = "0" repeatbehavior = "forever" storyboard. targetname = "spinningrotatetransform" storyboard. targetproperty = "angle" to = "360"/> </storyboard> </Phone: phoneapplicationpage. resources>

Step 3:CodeAdd to mainpage. XAML:

<Stackpanel X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0 "background =" red "> <image margin =" 10, 10 "Height =" 50 "width =" 50 "Source ="/spinner.png "stretch =" Uniform "> <image. rendertransform> <rotatetransform X: Name = "spinningrotatetransform" centerx = "25" centery = "25"/> </image. rendertransform> </image> </stackpanel>

Step 4: Add two buttons to start and end the animation.

 
<Button content = "Start Animation" Click = "btnstart_click"/> <button content = "Stop Animation" Click = "btnstop_click"/>

 
Private void btnstart_click (Object sender, routedeventargs e) {This. spinninganimation. Begin ();} private void btnstop_click (Object sender, inclue) {This. spinninganimation. Stop ();}

Step 5: if you do not see the effect after running, the color of the rotated image is usually the same as the background color of the page. After changing the color, you can see it. Here you can use an opaque mask, add the following code:

 
<Ellipse fill = "{staticresource phoneforegroundbrush}" Height = "50" width = "50" margin = "10, 10"> <ellipse. opacitymask> <imagebrush imagesource = "/spinner.png" stretch = "Uniform"/> </ellipse. opacitymask> <ellipse. rendertransform> <rotatetransform X: Name = "spinningrotatetransform" centerx = "25" centery = "25"/> </ellipse. rendertransform> </ellipse>

The final code is as follows:

Mainpage. XAML:

<Phone: phoneapplicationpage X: class = "spinningprogressbar. mainpage "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "xmlns: D =" http://schemas.microsoft.com/expression/blend/2008" Xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006" MC: ignorable = "D" fontfamily = "{staticresource quota}" fontsize = "{staticresource quota}" foreground = "{staticresource quota}" supportedorientations = "portrait" orientation = "portrait" Shell: systemtray. isvisible = "true"> <Phone: phoneapplicationpage. resources> <storyboard X: Name = "spinningan Imation "> <doubleanimation autoreverse =" false "Duration =" 0: 0 "from =" 0 "repeatbehavior =" forever "storyboard. targetname = "spinningrotatetransform" storyboard. targetproperty = "angle" to = "360"/> </storyboard> </Phone: phoneapplicationpage. resources> <! -- Layoutroot is the root grid where all page content is placed --> <grid X: Name = "layoutroot" background = "Transparent"> <grid. rowdefinitions> <rowdefinition Height = "Auto"/> <rowdefinition Height = "*"/> </grid. rowdefinitions> <! -- Titlepanel contains the name of the application and page title --> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = "12, 17, "> <textblock text =" my application "style =" {staticresource phonetextnormalstyle} "margin =" "/> <textblock text =" Page name "margin =" 9, -7,0, 0 "style =" {staticresource phonetexttitle1style} "/> </stackpanel> <! -- Contentpanel-place additional content here --> <stackpanel X: Name = "contentpanel" grid. row = "1" margin = "12, 0, "> <ellipse fill =" {staticresource phoneforegroundbrush} "Height =" 50 "width =" 50 "margin =" "> <ellipse. opacitymask> <imagebrush imagesource = "/spinner.png" stretch = "Uniform"/> </ellipse. opacitymask> <ellipse. rendertransform> <rotatetransform X: Name = "spinningrotatetransform" centerx = "25" centery = "25"/> </ellipse. rendertransform> </ellipse> <button content = "Start Animation" Click = "btnstart_click"/> <button content = "Stop Animation" Click = "btnstop_click"/> </stackpanel> </GRID> </phone: phoneapplicationpage>

Mainpage. XAML. CS

 
Using system; using system. collections. generic; using system. LINQ; using system. net; using system. windows; using system. windows. controls; using system. windows. navigation; using Microsoft. phone. controls; using Microsoft. phone. shell; using spinningprogressbar. resources; namespace spinningprogressbar {public partial class mainpage: phoneapplicationpage {// constructor public mainpage () {initializecomponent ();} private void btnstart_click (Object sender, routedeventargs e) {This. spinninganimation. begin ();} private void btnstop_click (Object sender, routedeventargs e) {This. spinninganimation. stop ();}}}

Source codeDownload here: http://www.windowsphonegeek.com/upload/articles/SpinningAnimation.zip

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.