WPF ProgressBar实现实时进度效果
作者:秋秋_瑶瑶 发布时间:2023-01-14 08:05:49
标签:WPF,ProgressBar,进度
本文实例为大家分享了WPF ProgressBar实现实时进度的具体代码,供大家参考,具体内容如下
简单测试,页面如图:
利用上班的一点点空闲时间,做了个wpf progressbar的例子,觉得有潜力可挖,故放上来供大家参考,有写的更好的请留言哦,方便交流学习,谢谢
这个xaml:
<Page x:Class="WpfBrowserAppDrill.ProgressBarPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Title="ProgressBarPage" Loaded="Page_Loaded">
<Grid>
<Button Margin="10" Click="Button_Click" VerticalAlignment="Top" Height="23" Width="100">进度条控制</Button>
<TextBlock Name="txtJD" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="50">当前进度:</TextBlock>
<ProgressBar Height="20" HorizontalAlignment="Center" Margin="8,167,0,0"
Name="pb_import" VerticalAlignment="Top" Width="500" />
</Grid>
</Page>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
namespace WpfBrowserAppDrill
{
/// <summary>
/// ProgressBarPage.xaml 的交互逻辑
/// </summary>
public partial class ProgressBarPage : Page
{
public ProgressBarPage()
{
InitializeComponent();
}
private void beginImport()
{
double value = 0;
double total = 100d;//得到循环次数
while (value < total)
{
double jd = Math.Round(((value + 1) * (pb_import.Maximum / total)), 4);
pb_import.Dispatcher.Invoke(new Action<System.Windows.DependencyProperty, object>(pb_import.SetValue),
System.Windows.Threading.DispatcherPriority.Background,
ProgressBar.ValueProperty,
jd);
//这里是加数据或费时的操作,我这里让它挂起300毫秒
Thread.Sleep(300);
txtJD.Text = "当前的进度是:" + (value + 1) + "(实际值)" + jd + "(百分比)";
value++;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
beginImport();
////new Thread(new ThreadStart(beginImport)).Start();
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
pb_import.Maximum = 100;
pb_import.Value = 0;
}
}
}
来源:https://blog.csdn.net/qiulei_21/article/details/9130271


猜你喜欢
- 随着手机性能的提高,以及iOS和Android两个平台的普及,更多的App都会选择两个平台的App都进行开发,在有些时候,为了更加快速的开发
- 理解并使用设计模式,能够培养我们良好的面向对象编程习惯,同时在实际应用中,可以如鱼得水,享受游刃有余的乐趣。Proxy是比较有用途的一种模式
- 前言Go 语言比 Java 语言性能优越的一个原因,就是轻量级线程Goroutines(协程Coroutine)。本篇文章深入分析下 Jav
- 本文实例讲述了C#编程之事务用法。分享给大家供大家参考,具体如下:ado.net2.0的SqlTransaction使用方法/////ado
- 前言WebJar官网:https://www.webjars.org/,对于任何与Servlet 3兼容的容器,WEB-INF/lib目录中
- 提到Java发送HTTP请求,大家首先想到的是用apache的HttpClient,或者squareup的OkHttp。而在Java11之前
- 本文实例为大家分享了Android实现自动转圈效果展示的具体代码,供大家参考,具体内容如下在values文件夹下创建attrs.xml<
- state:比较常用,各种状态都可以用它,但是它更着重于一种心理状态或者物理状态。Status:用在人的身上一般是其身份和地位,作“状态,情
- 读取resources下文件的方法网上有问答如下:问:new FileInputStream("src/main/resource
- /*同步函数当函数中的代码全部放在了同步代码块中,那么这个函数就是同步函数*///同步函数的锁是this锁,this是一个引用,this指向
- 前言在服务器上,当我们启动了tomcat,就可以以http://ip地址:8080/文件路径/文件名的方式,进行访问到我们服务器上处于tom
- C# 后台:.ToString("dd-MMM-yyyy", System.Globalization. DateTim
- Java是一门天然的面向对象的语言。而所有我们手动创造出来的类,都继承于同一个类,即Object类。可以看一下Object类的结构nativ
- 很多同学对于overload和override傻傻分不清楚,建议不要死记硬背概念性的知识,要理解着去记忆。  
- 自定义Starter命名规则注意artifactId的命名规则,Spring官方Starter通常命名为spring-boot-starte
- 本文实例为大家分享了C#重写DataGridView的实例代码,供大家参考,具体内容如下using System;using S
- 本文实例分析了Android中ImageView用法。分享给大家供大家参考,具体如下:猜牌游戏大家可能以前都玩过,这里我们用这个小游戏来说明
- 我们通常在使用Java 调用脚本的时候,会使用 Runtime 类如:// 打开浏览器并访问 http://localh
- iOS定位 - 普通定位(没有地图) - 反地理编码(得到具体位置),下面通过代码给大家详解,代码如下:#import <CoreLo
- 多说无益,贴代码:/** * 校验银行卡卡号 * * @param cardId &nbs