Windows 8實用竅門系列:7.Windows 8 中的三種進度條和兩種定時器

來源:互聯網
上載者:User

  在Windows 8中的預設進度條也與時俱進,和之前Silverlight中的不一樣。本文將講述三種不同的進度條,另外在本文中也會將兩種定時器。

進度

  主要屬性:

    Value:當前進度值。

    Maximum:最大進度值。

    IsIndeterminate:指定進度條是否確定。

  確定進度條:進度明確的進度條,已完成進度以另外一種顏色顯示

    關鍵代碼:

  <ProgressBar Maximum="100" Value="0"  Height="20" Name="probar1"                     IsIndeterminate="False" Margin="275,167,966,581"></ProgressBar>

 

  不確定進度條:進度不明確的進度條,不可預知當前進度

    關鍵代碼:

 <ProgressBar IsIndeterminate="True" Width="80" Height="10" Margin="600,167,566,591"/>

 

  不確定進度環:進度不明確的進度環,不可預知當前進度

    關鍵代碼:

   <ProgressRing IsActive="True" Height="58" Margin="1000,167,299,543" Width="67"/>

 

定時器

  延遲定時器:只運行一次,延遲X毫秒啟動並執行定時器。

    關鍵代碼:

       private void Button_Click_1(object sender, RoutedEventArgs e)        {            DelayTimer();        }        /// <summary>        /// 延遲定時器        /// </summary>        private void DelayTimer()        {            //設定延遲定時器            ThreadPoolTimer tptimer = ThreadPoolTimer.CreateTimer(async (timer) =>            {                await Dispatcher.RunAsync(                    CoreDispatcherPriority.High, () =>                    {                        this.probar1.Value += 20;                    });            }, TimeSpan.FromMilliseconds(3000));        }

  迴圈定時器:迴圈運行N次,每次延遲X毫秒的定時器。

    關鍵代碼:

        private void Button_Click_2(object sender, RoutedEventArgs e)        {            PeriodicTimer();        }        /// <summary>        /// 迴圈定時器        /// </summary>        private void PeriodicTimer()        {            //迴圈定時器            ThreadPoolTimer tptimer = ThreadPoolTimer.CreatePeriodicTimer(                async (timer) =>                {                    await Dispatcher.RunAsync(                        CoreDispatcherPriority.High, () =>                        {                            this.probar1.Value = this.probar1.Value + 1;                        });                },                TimeSpan.FromMilliseconds(100));        }

  最後我們來看運行和如需源碼請點擊Win8Progress.rar下載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.