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的了解还不是足够深入,还是摸索着做了一个.这篇文章介 ...
随机推荐
- 转载:C++之高精度算法
C++之高精度算法 注意:本文转载自http://blog.sina.com.cn/s/blog_4fdb102b010087ng.html,十分感谢原作者:忍者 前言:由于计算机运算是有模运算 ...
- Yii中用递归方法实现无限级分类
用递归方法实现多级分类,适合分级不太多的分类,如三到四级. 数据库结构: Model中(Category.php) /** * 获取全部分类信息 */ public function getAllca ...
- 三种纯CSS实现三角形的方法
看到像上图这样的 tip 的小三角,你会怎么办? 切个图上去?恩,不错,简单,兼容性也一级棒,不但好控制,那点小东西也增加不了多少图片的大小.但有没有更好更讲究技巧的办法呢?哈哈,那必须有啊,而且还不 ...
- Shell数组:shell数组的定义、数组长度
Shell在编程方面比Windows批处理强大很多,无论是在循环.运算. bash支持一维数组(不支持多维数组),并且没有限定数组的大小.类似与C语言,数组元素的下标由0开始编号.获取数组中的元素要利 ...
- xom报错 Exception in thread "main" java.net.UnknownHostException: file
Exception in thread "main" java.net.UnknownHostException: file at java.net.AbstractPlainSo ...
- CSS备忘笔记
一.CSS的概念 CSS(Cascading Style Sheet),中文译为层叠样式表,它是用于控制网页样式并允许将样式信息与网页内容分离的一种标记性语言. 二.CSS使用方式 使用CSS控制页面 ...
- iptables的实战整理
一.iptables使用场景: 内网情况下使用:在大并发的情况下不要开iptables否则影响性能 二.iptables出现下面的问题: 在yewufa ...
- Java NIO使用及原理分析(三)
在上一篇文章中介绍了缓冲区内部对于状态变化的跟踪机制,而对于NIO中缓冲区来说,还有很多的内容值的学习,如缓冲区的分片与数据共享,只读缓冲区等.在本文中我们来看一下缓冲区一些更细节的内容. 缓冲区的分 ...
- <%%>与<%=%>区别
1.<%= %>只能得到当前面定义的值.即你在这个页里有<% int a=100%>--你在下面才可以使用<%=a%>2.${ }这个是el表达式.可以从上下文中得 ...
- win10清理C盘
用win10系统也不是很久,发现C盘容量越来越小了,于是乎扫描了一下,发现有两个文件容量很大 C:/hiberfil.syssize:1660444672 C:/swapfile.syssize:26 ...