在Windows 8中的默認(rèn)進(jìn)度條也與時(shí)俱進(jìn),和之前Silverlight中的不一樣。本文將講述三種不同的進(jìn)度條,另外在本文中也會(huì)將兩種定時(shí)器。
進(jìn)度條
主要屬性:
Value:當(dāng)前進(jìn)度值。
Maximum:最大進(jìn)度值。
IsIndeterminate:指定進(jìn)度條是否確定。
確定進(jìn)度條:進(jìn)度明確的進(jìn)度條,已完成進(jìn)度以另外一種顏色顯示
關(guān)鍵代碼:
ProgressBar Maximum="100" Value="0" Height="20" Name="probar1"
IsIndeterminate="False" Margin="275,167,966,581">/ProgressBar>
不確定進(jìn)度條:進(jìn)度不明確的進(jìn)度條,不可預(yù)知當(dāng)前進(jìn)度
關(guān)鍵代碼:
ProgressBar IsIndeterminate="True" Width="80" Height="10" Margin="600,167,566,591"/>
不確定進(jìn)度環(huán):進(jìn)度不明確的進(jìn)度環(huán),不可預(yù)知當(dāng)前進(jìn)度
關(guān)鍵代碼:
ProgressRing IsActive="True" Height="58" Margin="1000,167,299,543" Width="67"/>
定時(shí)器
延遲定時(shí)器:只運(yùn)行一次,延遲X毫秒運(yùn)行的定時(shí)器。
關(guān)鍵代碼:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
DelayTimer();
}/p>
p> /// summary>
/// 延遲定時(shí)器
/// /summary>
private void DelayTimer()
{
//設(shè)置延遲定時(shí)器
ThreadPoolTimer tptimer = ThreadPoolTimer.CreateTimer(async (timer) =>
{
await Dispatcher.RunAsync(
CoreDispatcherPriority.High, () =>
{
this.probar1.Value += 20;
});
}, TimeSpan.FromMilliseconds(3000));
}
循環(huán)定時(shí)器:循環(huán)運(yùn)行N次,每次延遲X毫秒的定時(shí)器。
關(guān)鍵代碼:
private void Button_Click_2(object sender, RoutedEventArgs e)
{
PeriodicTimer();
}/p>
p> /// summary>
/// 循環(huán)定時(shí)器
/// /summary>
private void PeriodicTimer()
{
//循環(huán)定時(shí)器
ThreadPoolTimer tptimer = ThreadPoolTimer.CreatePeriodicTimer(
async (timer) =>
{
await Dispatcher.RunAsync(
CoreDispatcherPriority.High, () =>
{
this.probar1.Value = this.probar1.Value + 1;
});
},
TimeSpan.FromMilliseconds(100));
}
最后我們來看運(yùn)行效果圖和如需源碼請(qǐng)點(diǎn)擊Win8Progress_jb51net 下載。效果如下圖
![](/d/20211018/c9e9d619774f9295ec07d341c102504c.gif)