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的了解还不是足够深入,还是摸索着做了一个.这篇文章介 ...
随机推荐
- 关于yuv 的pack(紧缩格式)和planner(平面格式)格式 [转]
关于yuv 格式 YUV 格式通常有两大类:打包(packed)格式和平面(planar)格式.前者将 YUV 分量存放在同一个数组中,通常是几个相邻的像素组成一个宏像素(macro-pixel);而 ...
- Tornado基本使用
一.快速上手 #!/usr/bin/env python # -*- coding:utf-8 -*- import tornado.ioloop import tornado.web class M ...
- 再次分享 pyspider 爬虫框架 - V2EX
再次分享 pyspider 爬虫框架 - V2EX block
- Uber入驻四川乐山峨眉地区
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 【Java重构系列】重构31式之搬移方法
重构第二式:搬移方法 (Refactoring 2: Move Method) 毋容置疑,搬移方法(Move Method)应该是最常用的重构手段之一,正因为太常用而且较为简单,以至于很多人并不认为它 ...
- android4.0 FaceDetection笔记
这几天研究了下andoid4.0.3的FaceDetection这里写一下大致的流程,方便日后查阅. 相关说明可以在这里找到: frameworks/base/docs/html/guide/topi ...
- http协议和web本质
转载:http://www.cnblogs.com/dinglang/archive/2012/02/11/2346430.html http协议和web本质 当你在浏览器地址栏敲入“http://w ...
- EPPlus与Excel完美的结合
本文转载:http://www.cnblogs.com/olartan/archive/2012/07/14/2591711.html 笔者近期在公司项目中需要生产比较复杂的Excel报表, 问题点是 ...
- WinForm MessageBox 提示对话框
public class MessageUtil { /// <summary> /// 显示一般的提示信息 /// </summary> /// <param name ...
- [D3] 11. Basic D3 chart interactivity on(), select(this), classed(class, trueorfalse)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...