2021-08-08 WPF控件专题 ProgressBar控件详解
【摘要】
1.ProgressBar 控件介绍
进度条 :显示某个操作的进度过程 。
Maximum Minimum Orientation Value IsIndeterminate
2.具体案例
<...
1.ProgressBar 控件介绍
进度条 :显示某个操作的进度过程 。
Maximum Minimum Orientation Value IsIndeterminate
2.具体案例
<Grid>
<!--Orientation 进度条的方向 默认水平 IsIndeterminate 指示进度是显示实际值 true 连续进度反馈-->
<ProgressBar HorizontalAlignment="Left" Orientation="Vertical" IsIndeterminate="True" Value="40" Minimum="0" Maximum="80" Height="299" Margin="49,89,0,0" VerticalAlignment="Top" Width="98"/>
<ProgressBar Name="pbar2" HorizontalAlignment="Left" Minimum="0" Maximum="100" Orientation="Horizontal" SmallChange="2" Height="29" Margin="287,201,0,0" VerticalAlignment="Top" Width="412" ValueChanged="Pbar2_ValueChanged" >
</ProgressBar>
<Button Content="加载" HorizontalAlignment="Left" Margin="287,328,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<Label Name="lblVal" HorizontalAlignment="Left" Margin="287,252,0,0" VerticalAlignment="Top" Height="28" Width="51"/>
</Grid>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
private void Button_Click(object sender, RoutedEventArgs e)
{
//pbar2.Value = 0;
//for (int i = 0; i < pbar2.Maximum; i++)
//{
// pbar2.Value = i;
// lblVal.Content = pbar2.Value + "%";
// Thread.Sleep(100);
//}
int max = 50;
Task.Run(() =>
{
for (int i = 0; i <= max; i++)
{
pbar2.Dispatcher.Invoke(() =>
{
pbar2.Value = i;
//lblVal.Content = pbar2.Value + "%";
});
Thread.Sleep(100);
}
});
}
private void Pbar2_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
lblVal.Content = e.NewValue + "%";
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
文章来源: codeboy.blog.csdn.net,作者:愚公搬代码,版权归原作者所有,如需转载,请联系作者。
原文链接:codeboy.blog.csdn.net/article/details/119522870
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)