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的了解还不是足够深入,还是摸索着做了一个.这篇文章介 ...
随机推荐
- patch与diff的恩怨
一.概述 diff和patch是一对相辅相成的工具,在数学上来说,diff类似于对两个集合的差运算,patch类似于对两个集合的和运算.diff比较两个文件或文件集合的差异,并记录下来,生成一个dif ...
- hdoj 5461 Largest Point
Largest Point Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- 安装Office时出现windows installer服务不能更新一个或多个受保护的windows文件错误的解决方法
今天在Windows XP上安装Microsoft Office 2010时,总是遇到“Windows Installer服务不能更新一个或多个受保护的windows文件,安装失败,正在回滚更改”提示 ...
- HighCharts 后台加载数据的时候去掉默认的 series
var chart; var options = { chart: { renderTo: 'container', type:'line' }, title: { text: '历史趋势时序图', ...
- 大型Web应用运行时 PHP负载均衡指南
如今,“大型服务器”模式的时代已经过去,我们在运行一些大的Web应用时候,可以使用各种各样的负载均衡技术,这是一种更可行的方法,将使硬件成本降至最低. 过去当运行一个大的web应用时候意味着需要运行一 ...
- Windows操作系统的历史
30 years ago Windows was first released, see how much it has changed回顾了Windows操作系统的历史. 1985, Windows ...
- Zend Framework 2参考Zend\Authentication(数据库表认证)
+ 转载自:Zend Framework 2参考Zend\Authentication(数据库表认证) 介绍 Zend\Authentication\Adapter\DbTable提供对存储在数据库表 ...
- 解决IE11不能进行webTest脚本录制的方法
当win7的ie8升级到ie11后,我的vs2012里的web性能测试用不了了,在打开IE11后,录制栏不见了,在网上找了很多资料没有结果,最后,在IE工具里发展了原因 工具->管理加载项-&g ...
- Run-Time Check Failure #2 - Stack around the variable 'ucPriKey' was corrupt
Run-Time Check Failure #2 一般是栈被破坏,你的代码可能有缓冲区溢出一类的问题. Run-Time Check Failure #2 - Sta ...
- 精《记叙“tom”4年的软件开发之旅》
1.引言 本篇文章是记叙tom四年的软件开发从业经历,虽然他资历不长,况且本身也是个菜鸟,但他也曾有过荣誉.迷茫.困惑与选择,在这里他希望通过自己所经历过的事情分享给大家,给那些真正热爱软件开发的同学 ...