2021-08-14 WPF控件专题 ProgressBar控件详解

Posted 微软MVP Eleven

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-08-14 WPF控件专题 ProgressBar控件详解相关的知识,希望对你有一定的参考价值。

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>
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 + "%";
   
      
}

以上是关于2021-08-14 WPF控件专题 ProgressBar控件详解的主要内容,如果未能解决你的问题,请参考以下文章

2021-08-14 WPF控件专题 ProgressBar控件详解

2021-08-14 WPF控件专题 DatePicker 控件详解

2021-08-14 WPF控件专题 ListBox控件详解

2021-08-13 WPF控件专题 ComboBox 控件详解

2021-08-19 WPF控件专题 TabControl 控件详解

2021-08-09 WPF控件专题 Button控件详解