//Create a Delegate that matches the Signature of the ProgressBar's SetValue method
private delegate void UpdateProgressBarDelegate(System.Windows.DependencyProperty dp, Object value);
private void Process()
{
//Configure the ProgressBar
ProgressBar1.Minimum = 0;
ProgressBar1.Maximum = short.MaxValue;
ProgressBar1.Value = 0;
//Stores the value of the ProgressBar
double value = 0;
//Create a new instance of our ProgressBar Delegate that points
// to the ProgressBar's SetValue method.
var updatePbDelegate = new UpdateProgressBarDelegate(ProgressBar1.SetValue); //Tight Loop: Loop until the ProgressBar.Value reaches the max
do
{
value += 1; /*Update the Value of the ProgressBar:
1) Pass the "updatePbDelegate" delegate that points to the ProgressBar1.SetValue method
2) Set the DispatcherPriority to "Background"
3) Pass an Object() Array containing the property to update (ProgressBar.ValueProperty) and the new value */
Dispatcher.Invoke(updatePbDelegate,
System.Windows.Threading.DispatcherPriority.Background,
new object[] {RangeBase.ValueProperty, value}); } while (ProgressBar1.Value <= ProgressBar1.Maximum); //////////////////////////////////////////
<ProgressBarMinimum="0"Maximum="100"Name="pbStatus"/>
privatevoidWindow_ContentRendered(object sender,EventArgs e)
                {
                        BackgroundWorker worker =newBackgroundWorker();
                        worker.WorkerReportsProgress=true;
                        worker.DoWork+= worker_DoWork;
                        worker.ProgressChanged+= worker_ProgressChanged;                         worker.RunWorkerAsync();
                }                 void worker_DoWork(object sender,DoWorkEventArgs e)
                {
                        for(int i =0; i <100; i++)
                        {
                                (sender asBackgroundWorker).ReportProgress(i);
                                Thread.Sleep(100);
                        }
                }                 void worker_ProgressChanged(object sender,ProgressChangedEventArgs e)
                {
                        pbStatus.Value= e.ProgressPercentage;
                }

Indeterminate

<ProgressBarMinimum="0"Maximum="100"Name="pbStatus"IsIndeterminate="True"/>

ProgressBar with text:

<GridMargin="20">
        <ProgressBarMinimum="0"Maximum="100"Value="75"Name="pbStatus"/>
        <TextBlockText="{Binding ElementName=pbStatus, Path=Value, StringFormat={}{0:0}%}"HorizontalAlignment="Center"VerticalAlignment="Center"/>
    </Grid>

<Window x:Class="ProgressBarTutorial.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="240" Width="446" Loaded="Window_Loaded">
    <Grid>
        <ProgressBar Margin="10,10,0,13" Name="PBar" HorizontalAlignment="Left" 
                 VerticalAlignment="Top" Width="300" Height="30" Value="60" FlowDirection="LeftToRight">            
        </ProgressBar>
        <StatusBar Name="sbar" Grid.Column="0" Grid.Row="5" VerticalAlignment="Bottom" Background="Beige" >
            <StatusBarItem>
                <TextBlock>StatusBar</TextBlock>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>

cs:

private Timer aTimer;

public Window1()
        {
            InitializeComponent();
            CreateDynamicProgressBarControl();
        }

private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Duration duration = new Duration(TimeSpan.FromSeconds(20));
            DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);
            PBar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
        }

private void CreateDynamicProgressBarControl()
        {
            ProgressBar progbar = new ProgressBar();
            progbar.IsIndeterminate = false;
            progbar.Orientation = Orientation.Horizontal;
            progbar.Width = 150;
            progbar.Height = 15;
            Duration duration = new Duration(TimeSpan.FromSeconds(10));
            DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
            progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
            sbar.Items.Add(progbar);
        }

////////////////////////////////////////////////////////////////////////////////////

<StatusBar Name="sbar" Grid.Column="0" Background="Beige" Margin="8,171.04,-8,177" >
            <StatusBarItem>
                <TextBlock Width="110.657" Height="22.96">StatusBar</TextBlock>
            </StatusBarItem>
        </StatusBar>

private void MakeIndeterminate(object sender, RoutedEventArgs e)
        {
            sbar.Items.Clear();
            Label lbl = new Label();
            lbl.Background = new LinearGradientBrush(Colors.Pink, Colors.Red, 90);
            lbl.Content = "Indeterminate ProgressBar.";
            sbar.Items.Add(lbl);
            ProgressBar progbar = new ProgressBar();
            //progbar.Background = Brushes.Gray;
            progbar.Foreground = Brushes.LightBlue;
            progbar.Width = 150;
            progbar.Height = 15;
            progbar.IsIndeterminate = true;
            sbar.Items.Add(progbar);
        }

WPF 进度条的更多相关文章

  1. WPF 进度条ProgressBar

    今天研究了一下wpf的进度条ProgressBar 1.传统ProgressBar WPF进度条ProgressBar 这个控件,如果直接写到循环里,会死掉,界面会卡死,不会有进度.需要把进度条放到单 ...

  2. WPF进度条系列②旋转小圆圈

     写在之前: 关于WPF的样式,我也是学习了很多朋友的文章才有了下面的东西,因为时间有些久远 & 备份的链接也都不在了. 所以,究竟是看过哪些文章,也是记不清楚了…… 请见谅. ------- ...

  3. C# WPF 进度条,根据读取数据显示进度条进度,根据Excel文件读取数据,进度条样式

    后台代码: //导入 private void Border_MouseLeftButtonUp_2(object sender, MouseButtonEventArgs e) { var path ...

  4. wpf 进度条 下拉

    <Window x:Class="WpfApplication1.MainWindow"        xmlns="http://schemas.microsof ...

  5. WPF进度条

    ProgressBar控件与传统WinForm使用方法完全一样,我们只需关注: Minimum——最小值,默认为0: Maximum——最大值,默认为100. Value——当前值.   关键是它的控 ...

  6. 继续聊WPF——进度条

    ProgressBar控件与传统WinForm使用方法完全一样,我们只需关注: Minimum——最小值,默认为0: Maximum——最大值,默认为100. Value——当前值.   关键是它的控 ...

  7. WPF进度条系列①滑动小圆点

     写在之前: 关于WPF的样式,我也是学习了很多朋友的文章才有了下面的东西,因为时间有些久远 & 备份的链接也都不在了. 所以,究竟是看过哪些文章,也是记不清楚了…… 请见谅. ------- ...

  8. Photoshop和WPF双剑配合,打造炫酷个性的进度条控件

    现在如果想打造一款专业的App,UI的设计和操作的简便性相当重要.UI设计可以借助Photoshop或者AI等设计工具,之前了解到WPF设计工具Expression Blend可以直接导入PSD文件或 ...

  9. WPF自定义控件第一 - 进度条控件

    本文主要针对WPF新手,高手可以直接忽略,更希望高手们能给出一些更好的实现思路. 前期一个小任务需要实现一个类似含步骤进度条的控件.虽然对于XAML的了解还不是足够深入,还是摸索着做了一个.这篇文章介 ...

随机推荐

  1. ubuntu 手动添加jar到本地仓库

    前言:maven仓库的下载速度太慢了,而且有些jar不存在,或者加入自己开发的依赖包,还是要学会自己手动加入jar.下面以 javax.servlet-api为例. 1.获取下载的javax.serv ...

  2. Tornado源码探寻(请求到来)

    上一篇中介绍了tornado框架在客户端请求之前所做的准备(下图1.2部分),本质上就是创建了一个socket服务端,并进行了IP和端口的绑定,但是未执行 socket的accept方法,也就是未获取 ...

  3. POJ 3125 Printer Queue

    题目: Description The only printer in the computer science students' union is experiencing an extremel ...

  4. 关于一次Weblogic活动线程的问题处理

    Weblogic控制台监控发现 环境>>服务器>>你的服务器>>监控>>线程 中活动执行线程竟然是2000多.同一套系统在另一套平台上,并且访问的人不少 ...

  5. 升级cocoapods到1.2 beta版本的方法

    最近写Swfit3.0, 要用到一些框架, 然后就用cocoapods嘛, 结果说要cocoapods1.1.0版本才行, 而自己的是cocoapods1.0.1版本的, 所以就想着升级嘛, 结果就遇 ...

  6. PAT 1026. Table Tennis

    A table tennis club has N tables available to the public.  The tables are numbered from 1 to N.  For ...

  7. 读取txt正则匹配行写入txt

    StreamReader sr = new StreamReader("C:\\Users\\Administrator\\Desktop\\blogbbs\\dd.txt",En ...

  8. iOS APNS远程推送(史上最全步骤)

    /*****************************************1************************************************/ waterma ...

  9. 深入理解Fsync----JBD内核调试 专业打杂程序员 @github yy哥

    http://hustcat.github.io/ http://www.cnblogs.com/hustcat/p/3283955.html http://blog.sina.com.cn/s/ar ...

  10. Day05 - Python 常用模块

    1. 模块简介 模块就是一个保存了 Python 代码的文件.模块能定义函数,类和变量.模块里也能包含可执行的代码. 模块也是 Python 对象,具有随机的名字属性用来绑定或引用. 下例是个简单的模 ...