WPF 进度条
//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 进度条的更多相关文章
- WPF 进度条ProgressBar
今天研究了一下wpf的进度条ProgressBar 1.传统ProgressBar WPF进度条ProgressBar 这个控件,如果直接写到循环里,会死掉,界面会卡死,不会有进度.需要把进度条放到单 ...
- WPF进度条系列②旋转小圆圈
写在之前: 关于WPF的样式,我也是学习了很多朋友的文章才有了下面的东西,因为时间有些久远 & 备份的链接也都不在了. 所以,究竟是看过哪些文章,也是记不清楚了…… 请见谅. ------- ...
- C# WPF 进度条,根据读取数据显示进度条进度,根据Excel文件读取数据,进度条样式
后台代码: //导入 private void Border_MouseLeftButtonUp_2(object sender, MouseButtonEventArgs e) { var path ...
- wpf 进度条 下拉
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsof ...
- WPF进度条
ProgressBar控件与传统WinForm使用方法完全一样,我们只需关注: Minimum——最小值,默认为0: Maximum——最大值,默认为100. Value——当前值. 关键是它的控 ...
- 继续聊WPF——进度条
ProgressBar控件与传统WinForm使用方法完全一样,我们只需关注: Minimum——最小值,默认为0: Maximum——最大值,默认为100. Value——当前值. 关键是它的控 ...
- WPF进度条系列①滑动小圆点
写在之前: 关于WPF的样式,我也是学习了很多朋友的文章才有了下面的东西,因为时间有些久远 & 备份的链接也都不在了. 所以,究竟是看过哪些文章,也是记不清楚了…… 请见谅. ------- ...
- Photoshop和WPF双剑配合,打造炫酷个性的进度条控件
现在如果想打造一款专业的App,UI的设计和操作的简便性相当重要.UI设计可以借助Photoshop或者AI等设计工具,之前了解到WPF设计工具Expression Blend可以直接导入PSD文件或 ...
- WPF自定义控件第一 - 进度条控件
本文主要针对WPF新手,高手可以直接忽略,更希望高手们能给出一些更好的实现思路. 前期一个小任务需要实现一个类似含步骤进度条的控件.虽然对于XAML的了解还不是足够深入,还是摸索着做了一个.这篇文章介 ...
随机推荐
- 如何引入一个Schema 文件
Schema(掌握如何引入一个schema文件) * 名称空间 : 指的是一个环境,所用的标签来自于哪个环境定义的. * 掌握引用schema文件: xml中引入s ...
- KVM虚拟化技术
KVM虚拟化技术 Qemu-kvm kvm virt-manager VNC Qemu-kvm创建和管理虚拟机 一.KVM简介 KVM(名称来自英语:Kernel-basedVirtual Machi ...
- hadoop启动后jps查不到namenode的解决办法
最近由于项目需要开始接触hadoop,在配置伪分布式启动后,jps查询进程发现少了namenode,而DataNode却存在. 下面是我的core-site.xml和hdfs-site.xml配置: ...
- [CSS] DOM Hierarchy Pseudo Classes :first-child :last-child :nth-child (demystified)
DOM hierarchy pseudo-classes allow you to style specific elements based on where they fall in the hi ...
- [Redux] Colocating Selectors with Reducers
We will learn how to encapsulate the knowledge about the state shape in the reducer files, so that t ...
- 如何判断Android系统的版本
随着Android版本的增多,在不同的版本中使用不同的设计是必须的,根据程序运行的版本来提供不同的功能.这涉及到如何在程序中判断Android系统的版本. 在Android api中的android. ...
- 1个小时学会ReactiveCocoa基本使用
来源:朱凯奇 链接:http://www.jianshu.com/p/5d966074741a 1.ReactiveCocoa简介 ReactiveCocoa(简称为RAC),是由Github开源的一 ...
- 插入ts以及判断列是否存在(支持多数据库)
1:增加ts.dr字段,先判断ts.dr字段是否存在,其中ts字段插入的是日期,默认值为当前插入的时间,dr字段是数值型,默认值为0 * 增加ts/dr字段 * * @param tableList ...
- Android(java)学习笔记168:Java异常分类
Java异常可分为3种: (1)编译时异常:Java.lang.Exception (2)运行期异常:Java.lang.RuntimeException (3)错误:Java.lang.Error
- Base64原理简介
Base64是一种编码方式,通常用于将二进制数据转换成可见字符的形式,该过程可逆. 过程大致如下: 1. 对64个可见字符,进行一个索引编码.索引是二进制的值,对应找到一个可见字符. Base64 编 ...