Windows Phone 7 development, progress bar Usage Details

Source: Internet
Author: User
The progress bar plays a very important role in the application. It can tell the user the progress of the current operation, so that the user will not lose patience while waiting, and then close the application. the progress bar of Windows Phone 7 has two styles: one is a small point that is rotated from left to right. The progress bar does not display the current progress, similar to the cycle style of the android progress bar; the other is a normal progress bar that can display the progress. Two effects are shown in the following figure:

  

The progress bar plays a very important role in the application. It can tell the user the progress of the current operation, so that you do not lose patience while waiting, and then close the application. the progress bar of Windows Phone 7 has two styles: one is a small point that is rotated from left to right. The progress bar does not display the current progress, similar to the cycle style of the android progress bar; the other is a normal progress bar that can display the progress. The effects of the two styles are as follows:

  

 

This example introduces three controls on the page. Two progressbar display two styles of progress bars and one button to enable the new thread to update the progress of progressbar, which is used for delegation, if you do not understand, refer:

The XAML code of several controls:

<Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0" background = "{X: NULL}">
<Progressbar Height = "54" horizontalalignment = "left"
Margin = "17,27, 0, 0" name = "progressbar1" verticalignment = "TOP"
Width = "390" isindeterminate = "true"/>
<! -- Isindeterminate is the key. This attribute determines the progressbar style. The default value is false, which indicates a general progress bar that can display progress, and true indicates a progress bar that cannot display progress. -->
<Progressbar Height = "59" horizontalalignment = "left"
Margin = "31,107, 374" name = "progressbar2" verticalignment = "TOP" width = ""/>
<Button content = "Update progressbar2" Height = "82"
Horizontalalignment = "Left" margin = "63,199," name = "button1"
Verticalalignment = "TOP" width = "260" Click = "button#click"/>
</GRID>

C # program 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;
Using Microsoft. Phone. controls;
Using system. Threading;

Namespace phoneapp3
{
Public partial class mainpage: phoneapplicationpage
{
Delegate void progressdelegate (int I );
// Declare the delegate type
// Delegate the content if you do not understand, see the http://www.pocketdigi.com/20110916/476.html has a detailed annotation
Progressdelegate;
// Declare the delegate
Public mainpage ()
{
Initializecomponent ();
}

Private void button#click (Object sender, routedeventargs E)
{
Progressdelegate = setprogress;
// Add the Update Progress Method to the Delegate
New thread (New threadstart (threadproc). Start ();
// Start a new thread

}
Private void setprogress (int I)
{
// This is the method for updating the progress bar
Progressbar2.value = I;
If (I = 100)
{
// Hide the progress bar if it reaches 100
Progressbar2.visibility = visibility. collapsed;
// Display method visibility. visibl
}
}
Private void threadproc ()
{// Method executed by the new thread
For (INT I = 0; I <= 100; I ++)
{
This. Dispatcher. begininvoke (progressdelegate, I );
// The thread calls the delegate to update the UI. The parameter is the delegate and the delegate parameter.
Thread. Sleep (1000 );
}

}
}
}
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.