当前位置: 首页 > news >正文

WPF 进度条(ProgressBar)示例一

本文讲述:WPF 进度条(ProgressBar)简单的样式修改和使用。

进度显示界面:使用UserControl把ProgressBar和进度值以及要显示的内容全部组装在UserControl界面中,方便其他界面直接进行使用。

<UserControl x:Class="DefProcessBarDemo.DefProcessBar"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"xmlns:local="clr-namespace:DefProcessBarDemo"mc:Ignorable="d"x:Name="MyWatingViewControl"><UserControl.Background><VisualBrush><VisualBrush.Visual><Border x:Name="ControlBackground"Background="Black"Opacity="0.45" /></VisualBrush.Visual></VisualBrush></UserControl.Background><Viewbox x:Name="myViewBox"Stretch="UniformToFill"StretchDirection="DownOnly"UseLayoutRounding="True"><Grid Margin="0 0 0 0"HorizontalAlignment="Center"VerticalAlignment="Center"MouseDown="Image_MouseDown"><Border CornerRadius="5"SnapsToDevicePixels="True"><Border.Effect><DropShadowEffect Color="#000000"BlurRadius="10"ShadowDepth="3"Opacity="0.35"Direction="270" /></Border.Effect><Border Background="#4a4a4a"CornerRadius="5"Margin="5"BorderBrush="#9196a0"BorderThickness="1"SnapsToDevicePixels="True"><Grid Width="500"Height="150"><Grid.RowDefinitions><RowDefinition Height="auto" /><RowDefinition Height="35" /><RowDefinition Height="*" /><RowDefinition Height="30" /></Grid.RowDefinitions><Image Name="CloseIco"Width="25"Height="25"Margin="0,0,0,0"MouseDown="Image_MouseDown"HorizontalAlignment="Right"VerticalAlignment="Top" /><StackPanel Grid.Row="1"Orientation="Horizontal"HorizontalAlignment="Center"><TextBlock Text="{Binding Message,ElementName=MyWatingViewControl}"FontSize="18"Foreground="Yellow"TextWrapping="WrapWithOverflow"TextTrimming="CharacterEllipsis"MaxWidth="450"VerticalAlignment="Bottom" /><TextBlock Text="("FontSize="18"Foreground="Yellow"VerticalAlignment="Bottom" /><TextBlock Text="{Binding ElementName=progressBar, Path=Value, StringFormat={}{0:0}%}"FontSize="18"Foreground="Yellow"FontFamily="楷体"VerticalAlignment="Bottom" /><TextBlock Text=")"FontSize="18"Foreground="Yellow"VerticalAlignment="Bottom" /></StackPanel><Grid  Grid.Row="2"HorizontalAlignment="Center"VerticalAlignment="Top"Margin="0 10"><ProgressBar x:Name="progressBar"Maximum="100"Height="25"Width="420"Foreground="Green"Background="LightGray"HorizontalContentAlignment="Center"VerticalContentAlignment="Center"Value="{Binding ProcessBarValue,ElementName=MyWatingViewControl}" /></Grid></Grid></Border></Border></Grid></Viewbox>
</UserControl>

进度显示界面:UserControl 后台逻辑实现,主要定义了进度值、显示的文本、以及UserControl的大小。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;namespace DefProcessBarDemo
{/// <summary>/// DefProcessBar.xaml 的交互逻辑/// </summary>public partial class DefProcessBar : UserControl{public DefProcessBar(){InitializeComponent();this.Loaded += WaitingView_Loaded;}void WaitingView_Loaded(object sender, RoutedEventArgs e){if (this.Parent != null){var root = (FrameworkElement)this.Parent;if (root != null){this.Width = root.ActualWidth;this.Height = root.ActualHeight;ControlBackground.Width = root.ActualWidth;ControlBackground.Height = root.ActualHeight;}}}#region Propertypublic string Message{get { return (string)GetValue(MessageProperty); }set { SetValue(MessageProperty, value); }}public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string), typeof(DefProcessBar),new PropertyMetadata(""));public double ProcessBarValue{get { return (double)GetValue(ProcessBarValueProperty); }set { SetValue(ProcessBarValueProperty, value); }}public static readonly DependencyProperty ProcessBarValueProperty = DependencyProperty.Register("ProcessBarValue", typeof(double), typeof(DefProcessBar),new PropertyMetadata(0.0));#endregionprivate void Image_MouseDown(object sender, MouseButtonEventArgs e){this.Visibility = Visibility.Hidden;}}
}

 在MainWindow界面中调用[进度显示界面],示例如下:

<Window x:Class="DefProcessBarDemo.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:DefProcessBarDemo"mc:Ignorable="d" Title="DefProcessBar" Width="600" Height="500"WindowStartupLocation="CenterScreen" x:Name="mainwnd"xmlns:pdb="clr-namespace:DefProcessBarDemo" Background="Teal"><StackPanel><Button Height="30" Width="120" Margin="20" Content="点击" Click="Button_Click"/><pdb:DefProcessBar VerticalAlignment="Center"ProcessBarValue="{Binding ExportValue, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"Message="{Binding ExportMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />        </StackPanel>
</Window>

 后台模拟进度变化,使用Task任务,更新进度值,代码示例如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;namespace DefProcessBarDemo
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window, System.ComponentModel.INotifyPropertyChanged{public MainWindow(){InitializeComponent();this.DataContext = this;}private string m_ExportMessage = "正在导出,请稍后....";/// <summary>/// /// <summary>public string ExportMessage{get { return m_ExportMessage; }set{m_ExportMessage = value;OnPropertyChanged("ExportMessage");}}private double m_ExportValue = 0.0;/// <summary>/// /// <summary>public double ExportValue{get { return m_ExportValue; }set{m_ExportValue = value;OnPropertyChanged("ExportValue");}}#region MyRegionpublic event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;protected void OnPropertyChanged(string propertyName){if (PropertyChanged != null){PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));}}#endregionprivate void Button_Click(object sender, RoutedEventArgs e){Task.Run(() =>{for(int i = 1; i < 101; i++){ExportValue++;System.Threading.Thread.Sleep(1000);if (ExportValue == 100)ExportMessage = "完成";}});string strRes = "";bool bRet = GetCmdResult("netsh wlan show profiles", out strRes);}}
}

运行时,点击【点击】按钮,即可看到进度持续不断地更新,界面如下图所示:

 



相关文章:

WPF 进度条(ProgressBar)示例一

本文讲述&#xff1a;WPF 进度条(ProgressBar)简单的样式修改和使用。 进度显示界面&#xff1a;使用UserControl把ProgressBar和进度值以及要显示的内容全部组装在UserControl界面中&#xff0c;方便其他界面直接进行使用。 <UserControl x:Class"DefProcessBarDemo…...

【C#】任务调度的实现原理与组件应用Quartz.Net

Quartz 是一个流行的开源作业调度库&#xff0c;最初由 Terracotta 开发&#xff0c;现在由 Terracotta 的一部分 Oracle 所有。它主要用于在 Java 应用程序中调度作业的执行。Quartz 使用了一种复杂的底层算法来管理任务调度&#xff0c;其中包括任务触发、执行、持久化以及集…...

UV - Python 包管理

文章目录 创建 uv 项目已有项目已有uv项目 创建 uv 项目 # 创建项目 uv init m3 # 创建环境 cd m3 uv venv --python 3.11 # 激活环境 source .venv/bin/activate # 添加库 uv add flask 如果创建项目后&#xff0c;给库取别的名字&#xff0c;add 的时候&#xff0c;会…...

pytorch torch.linalg模块介绍

torch.linalg 是 PyTorch 的 线性代数 (Linear Algebra) 子模块&#xff0c;它提供了许多 高效的矩阵操作和分解方法&#xff0c;类似于 NumPy 的 numpy.linalg 或 SciPy 的 scipy.linalg&#xff0c;但针对 GPU 加速和自动微分 进行了优化。 1. 矩阵基本运算 矩阵乘法 torc…...

光伏-报告显示,假期内,硅料端签单顺序发货相对稳定。若3月份下游存提产,则不排除硅料价格有上调预期。

据TrendForce集邦咨询报告显示&#xff0c;假期内&#xff0c;硅料端按照前期签单顺序发货&#xff0c;相对稳定。若3月份下游存提产&#xff0c;则不排除硅料价格有上调预期。 002306中科云网 旅游 | 公司为提供复合菜系特色餐饮的连锁企业&#xff0c;形成了以粤菜&#xff…...

【web自动化】指定chromedriver以及chrome路径

selenium自动化&#xff0c;指定chromedriver&#xff0c;以及chrome路径 对应这篇文章&#xff0c;可以点击查看&#xff0c;详情 from selenium import webdriverdef get_driver():# 获取配置对象option webdriver.ChromeOptions()option.add_experimental_option("de…...

顺丰数据分析(数据挖掘)面试题及参考答案

你觉得数据分析人员必备的技能有哪些? 数据分析人员需具备多方面技能,以应对复杂的数据处理与解读工作。 数据处理能力:这是基础且关键的技能。数据常以杂乱、不完整的形式存在,需通过清洗,去除重复、错误及缺失值数据,确保数据质量。例如,在电商销售数据中,可能存在价…...

Android studio:顶部导航栏Toolbar

主流APP在顶部都配有导航栏&#xff0c;在 Android 中&#xff0c;ActionBar 是默认启用的&#xff0c;它是位于屏幕顶部的一个工具栏&#xff0c;用来放置应用的标题、导航和操作菜单。 如果你想使用自定义的 Toolbar 来替代 ActionBar&#xff0c;应该先关闭它。可以通过设置…...

mmap 文件映射

&#x1f308; 个人主页&#xff1a;Zfox_ &#x1f525; 系列专栏&#xff1a;Linux 目录 一&#xff1a;&#x1f525; mmap介绍&#x1f98b; 基本说明&#x1f98b; 参数介绍&#x1f98b; 返回值 二&#xff1a;&#x1f525; demo代码&#x1f98b; 写入映射&#x1f98b…...

基于微信小程序的医院预约挂号系统的设计与实现

hello hello~ &#xff0c;这里是 code袁~&#x1f496;&#x1f496; &#xff0c;欢迎大家点赞&#x1f973;&#x1f973;关注&#x1f4a5;&#x1f4a5;收藏&#x1f339;&#x1f339;&#x1f339; &#x1f981;作者简介&#xff1a;一名喜欢分享和记录学习的在校大学生…...

【Linux】Socket编程—UDP

&#x1f525; 个人主页&#xff1a;大耳朵土土垚 &#x1f525; 所属专栏&#xff1a;Linux系统编程 这里将会不定期更新有关Linux的内容&#xff0c;欢迎大家点赞&#xff0c;收藏&#xff0c;评论&#x1f973;&#x1f973;&#x1f389;&#x1f389;&#x1f389; 文章目…...

2025年物联网相关专业毕业论文选题参考,文末联系,选题相关资料提供

一、智能穿戴解决方案研究方向 序号解决方案论文选题论文研究方向1智能腰带健康监测基于SpringBoot和Vue的智能腰带健康监测数据可视化平台开发研究如何利用SpringBoot和Vue技术栈开发一个数据可视化平台&#xff0c;用于展示智能腰带健康监测采集的数据&#xff0c;如心率、血…...

如何在WPS和Word/Excel中直接使用DeepSeek功能

以下是将DeepSeek功能集成到WPS中的详细步骤&#xff0c;无需本地部署模型&#xff0c;直接通过官网连接使用&#xff1a;1. 下载并安装OfficeAI插件 &#xff08;1&#xff09;访问OfficeAI插件下载地址&#xff1a;OfficeAI助手 - 免费办公智能AI助手, AI写作&#xff0c;下载…...

DeepSeek之Api的使用(将DeepSeek的api集成到程序中)

一、DeepSeek API 的收费模式 前言&#xff1a;使用DeepSeek的api是收费的 免费版&#xff1a; 可能提供有限的免费额度&#xff08;如每月一定次数的 API 调用&#xff09;&#xff0c;适合个人开发者或小规模项目。 付费版&#xff1a; 超出免费额度后&#xff0c;可能需要按…...

使用DeepSeek实现AI自动编码

最近deepseek很火&#xff0c;低成本训练大模型把OpenAI、英伟达等股票搞得一塌糊涂。那它是什么呢&#xff0c;对于咱们程序员编码能有什么用呢&#xff1f;DeepSeek 是一款先进的人工智能语言模型&#xff0c;在自然语言处理和代码生成方面表现出色。它经过大量代码数据训练&…...

30~32.ppt

目录 30.导游小姚-介绍首都北京❗ 题目​ 解析 31.小张-旅游产品推广文章 题目 解析 32.小李-水的知识❗ 题目​ 解析 30.导游小姚-介绍首都北京❗ 题目 解析 新建幻灯片-从大纲-重置-检查设计→主题对话框→浏览主题&#xff1a;考生文件夹&#xff08;注意&#x…...

Java的匿名内部类转为lamada表达式

在Java中&#xff0c;匿名内部类通常用于创建没有命名类的实例。例如&#xff0c;你可能需要创建一个实现了某个接口的匿名类&#xff0c;或者在需要重写某个方法时使用它。在Java 8及更高版本中&#xff0c;你可以使用Lambda表达式来替代传统的匿名内部类&#xff0c;使得代码…...

redis高级数据结构Stream

文章目录 背景stream概述消息 ID消息内容常见操作独立消费创建消费组消费 Stream弊端Stream 消息太多怎么办?消息如果忘记 ACK 会怎样?PEL 如何避免消息丢失?分区 Partition Stream 的高可用总结 背景 为了解决list作为消息队列是无法支持消息多播问题&#xff0c;Redis5.0…...

LeetCode781 森林中的兔子

问题描述 在一片神秘的森林里&#xff0c;住着许多兔子&#xff0c;但是我们并不知道兔子的具体数量。现在&#xff0c;我们对其中若干只兔子进行提问&#xff0c;问题是 “还有多少只兔子与你&#xff08;指被提问的兔子&#xff09;颜色相同&#xff1f;” 我们将每只兔子的…...

单硬盘槽笔记本更换硬盘

背景 本人的笔记本电脑只有一个硬盘槽&#xff0c;而且没有M.2的硬盘盒&#xff0c;只有一个移动硬盘 旧硬盘&#xff1a;512G 新硬盘&#xff1a;1T 移动硬盘&#xff1a;512G 参考链接&#xff1a;https://www.bilibili.com/video/BV1iP41187SW/?spm_id_from333.1007.t…...

DeerFlow效果展示:自动生成的深度研究报告与播客内容惊艳分享

DeerFlow效果展示&#xff1a;自动生成的深度研究报告与播客内容惊艳分享 1. DeerFlow核心能力概览 DeerFlow作为一款深度研究智能助手&#xff0c;整合了语言模型、网络搜索和代码执行能力&#xff0c;能够自动完成从信息收集到内容生成的全流程工作。其核心功能亮点包括&am…...

Graphormer部署指南:3.7GB纯Transformer图神经网络GPU快速启动

Graphormer部署指南&#xff1a;3.7GB纯Transformer图神经网络GPU快速启动 1. 项目概述 Graphormer是一种基于纯Transformer架构的图神经网络&#xff0c;专门为分子图&#xff08;原子-键结构&#xff09;的全局结构建模与属性预测而设计。这个3.7GB大小的模型在OGB、PCQM4M…...

基于AI政策路径与通胀预期模型的美联储决策分析:鲍威尔观望信号引发加息预期归零

摘要&#xff1a;本文通过构建AI政策路径预测模型&#xff0c;结合通胀预期识别系统、能源价格传导算法与劳动力市场评估框架&#xff0c;对美联储在当前环境下的利率决策逻辑进行分析&#xff0c;重点解析“观望策略”背后的模型依据及市场加息预期快速回落的原因。一、AI政策…...

nlp_structbert_sentence-similarity_chinese-large保姆级教学:模型路径自定义、多模型切换、Web界面汉化配置

nlp_structbert_sentence-similarity_chinese-large保姆级教学&#xff1a;模型路径自定义、多模型切换、Web界面汉化配置 1. 引言&#xff1a;为什么需要这个工具&#xff1f; 你是不是经常遇到这样的情况&#xff1a;需要判断两段中文文字是不是表达同一个意思&#xff0c;…...

Vue 中的 deep、v-deep 和 >>> 有什么区别?什么时候该用

点赞 收藏 学会&#x1f923;&#x1f923;&#x1f923; “你用 Element Plus 写了个按钮&#xff0c;想改下 hover 颜色&#xff0c;结果死活不生效&#xff01;最后查了半天&#xff0c;发现得加个 :deep() 才行” 其实&#xff0c;这是 Vue 中一个非常常见的坑&#xf…...

特朗普政府发布《国家人工智能立法框架》,多维度布局AI领域

【《国家人工智能立法框架》六大核心目标锚定AI发展方向】特朗普政府发布的《国家人工智能立法框架》&#xff0c;意在通过统一国家政策确保美国在AI领域的全球领先地位。该框架包含六大核心目标&#xff0c;分别是保护儿童与赋能家长、维护与强化美国社区、尊重知识产权与支持…...

HTML新手入门教程(二)

一、网页图像标签以及超链接 接着上篇文章&#xff0c;这次我们来学习一下图像标签、超链接标签如何使用&#xff0c;以及使用效果。本文章我们以<img>和<a>标签来展开教学。 在 HTML 中&#xff0c;<img>标签用于在网页中插入图像。它的作用是可以把文档中…...

生成单颗10mm级配的cluster骨料

PFC5.0代码&#xff0c;可以破碎的cluster&#xff0c;可模拟碎石、矿渣混凝土材料&#xff0c;ball与cluster颗粒&#xff0c;单轴压缩实验&#xff0c;内涵声发射事件数代码&#xff0c;分析统计ball与ball直接的裂纹数目&#xff0c;cluster内部破碎的裂纹数目上周帮同门调P…...

PX4仿真环境下的XTDrone实战:解决roslaunch常见错误的5个技巧

PX4仿真环境下的XTDrone实战&#xff1a;解决roslaunch常见错误的5个技巧 在无人机开发领域&#xff0c;PX4与ROS的结合为开发者提供了强大的仿真和测试平台。XTDrone作为基于PX4和ROS的开源无人机仿真框架&#xff0c;已经成为许多开发者和研究团队的首选工具。然而&#xff0…...

ai辅助开发:借助快马平台ai模型打造智能自适应的openclaw chrome数据抓取插件

今天想和大家分享一个最近用AI技术增强网页数据抓取效率的实践——开发一个叫OpenClaw的智能Chrome插件。这个插件的特别之处在于&#xff0c;它不仅能抓取数据&#xff0c;还能通过AI理解网页结构&#xff0c;自动适应不同网站&#xff0c;大大减少了手动编写抓取规则的工作量…...