Windows Phone 7开发,进度条ProgressBar使用详解
生活随笔
收集整理的這篇文章主要介紹了
Windows Phone 7开发,进度条ProgressBar使用详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
進度條在應用中的作用非常大,可以告訴用戶當前操作執行的進度,以免用戶在等待中失去耐心,進而關閉應 用.Windows Phone 7的進度條有兩種樣式,一種是從左往右循環滾動的小點點,這種進度條并不能顯示當前進度,類似于Android進度條的轉圈風格;另一種就是能顯示進度的 普通進度條,兩種樣式效果如下圖: 介紹一下這個實例,頁面上三
????????????<ProgressBar?Height="54"?HorizontalAlignment="Left"?
Margin="17,27,0,0"?Name="progressBar1"?VerticalAlignment="Top"?
Width="390"?IsIndeterminate="True"?/>
????????????<!--IsIndeterminate是關鍵,這個屬性確定了ProgressBar的樣式,默認是false,就是普通的能顯示進度的進度條,true就是不能顯示進度的進度條-->
????????????<ProgressBar?Height="59"?HorizontalAlignment="Left"?
Margin="31,107,0,0"?Name="progressBar2"?VerticalAlignment="Top"?Width="374"??/>
????????????<Button?Content="更新progressBar2"?Height="82"?
HorizontalAlignment="Left"?Margin="63,199,0,0"?Name="button1"?
VerticalAlignment="Top"?Width="260"?Click="button1_Click"?/>
????????</Grid>
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);
????????//聲明委托類型
????????//委托的內容如有不明白,見http://www.pocketdigi.com/20110916/476.html?有詳細注解
????????ProgressDelegate?progressDelegate;
????????//聲明委托
????????public?MainPage()
????????{
????????????InitializeComponent();
????????}
?
????????private?void?button1_Click(object?sender,?RoutedEventArgs?e)
????????{
????????????progressDelegate?=?SetProgress;
????????????//把更新進度方法添加進委托
????????????new?Thread(new?ThreadStart(ThreadProc)).Start();
????????????//開啟新線程
?
????????}
????????private?void?SetProgress(int?i)
????????{
????????????//這是更新進度條的方法
????????????progressBar2.Value?=?i;
????????????if?(i?==?100)
????????????{
????????????????//如果達到100,則隱藏進度條
????????????????progressBar2.Visibility?=?Visibility.Collapsed;
????????????????//顯示方法Visibility.Visibl
????????????}
????????}
????????private?void?ThreadProc()
????????{//新線程執行的方法
????????????for?(int?i?=?0;?i?<=?100;?i++)
????????????{
????????????????this.Dispatcher.BeginInvoke(progressDelegate,i);
????????????????//線程中調用委托來更新UI,參數是委托,以及委托的參數
????????????????Thread.Sleep(1000);
????????????}
?
????????}
????}
}
進度條在應用中的作用非常大,可以告訴用戶當前操作執行的進度,以免用戶在等待中失去耐心,進而關閉應用.Windows Phone 7的進度條有兩種樣式,一種是從左往右循環滾動的小點點,這種進度條并不能顯示當前進度,類似于Android進度條的轉圈風格;另一種就是能顯示進度的 普通進度條,兩種樣式效果如下圖:
?
介紹一下這個實例,頁面上三個控件,兩個ProgressBar分別顯示兩種風格的進度條,一個按鈕,用于開啟新線程更新ProgressBar的進度,這里用于了委托,如有不明白,參考:
幾個控件的XAML代碼:
<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"?VerticalAlignment="Top"?
Width="390"?IsIndeterminate="True"?/>
????????????<!--IsIndeterminate是關鍵,這個屬性確定了ProgressBar的樣式,默認是false,就是普通的能顯示進度的進度條,true就是不能顯示進度的進度條-->
????????????<ProgressBar?Height="59"?HorizontalAlignment="Left"?
Margin="31,107,0,0"?Name="progressBar2"?VerticalAlignment="Top"?Width="374"??/>
????????????<Button?Content="更新progressBar2"?Height="82"?
HorizontalAlignment="Left"?Margin="63,199,0,0"?Name="button1"?
VerticalAlignment="Top"?Width="260"?Click="button1_Click"?/>
????????</Grid>
C#程序代碼:
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);
????????//聲明委托類型
????????//委托的內容如有不明白,見http://www.pocketdigi.com/20110916/476.html?有詳細注解
????????ProgressDelegate?progressDelegate;
????????//聲明委托
????????public?MainPage()
????????{
????????????InitializeComponent();
????????}
?
????????private?void?button1_Click(object?sender,?RoutedEventArgs?e)
????????{
????????????progressDelegate?=?SetProgress;
????????????//把更新進度方法添加進委托
????????????new?Thread(new?ThreadStart(ThreadProc)).Start();
????????????//開啟新線程
?
????????}
????????private?void?SetProgress(int?i)
????????{
????????????//這是更新進度條的方法
????????????progressBar2.Value?=?i;
????????????if?(i?==?100)
????????????{
????????????????//如果達到100,則隱藏進度條
????????????????progressBar2.Visibility?=?Visibility.Collapsed;
????????????????//顯示方法Visibility.Visibl
????????????}
????????}
????????private?void?ThreadProc()
????????{//新線程執行的方法
????????????for?(int?i?=?0;?i?<=?100;?i++)
????????????{
????????????????this.Dispatcher.BeginInvoke(progressDelegate,i);
????????????????//線程中調用委托來更新UI,參數是委托,以及委托的參數
????????????????Thread.Sleep(1000);
????????????}
?
????????}
????}
}
轉載于:https://www.cnblogs.com/songtzu/archive/2012/04/10/2439959.html
新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!總結
以上是生活随笔為你收集整理的Windows Phone 7开发,进度条ProgressBar使用详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ORA-00119,ORA-00132
- 下一篇: PushMe(交互式)