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

wpf 进度条

一、

<Window x:Class="WpfApp.Windows.ProgressWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="现代进度条" Height="220" Width="420"WindowStartupLocation="CenterScreen"Background="#F5F6FA" FontFamily="Segoe UI"ResizeMode="NoResize"><Window.Resources><!-- 自定义圆角渐变进度条样式 --><Style x:Key="ModernProgressBar" TargetType="ProgressBar"><Setter Property="SnapsToDevicePixels" Value="True" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="ProgressBar"><Grid x:Name="Root" Height="20" ClipToBounds="True" SnapsToDevicePixels="True"><!-- 背景条 --><Border x:Name="PART_Track"Background="#E0E0E0"CornerRadius="10"Height="20" /><!-- 进度条指示 --><Border x:Name="PART_Indicator"Height="20"HorizontalAlignment="Left"CornerRadius="10"Width="0"><Border.Background><LinearGradientBrush StartPoint="0,0" EndPoint="1,0"><GradientStop Color="#0078D7" Offset="0" /><GradientStop Color="#4FC3F7" Offset="1" /></LinearGradientBrush></Border.Background></Border></Grid></ControlTemplate></Setter.Value></Setter></Style></Window.Resources><Grid><StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20" Width="360"><TextBlock Text="处理中,请稍候..." FontSize="18" FontWeight="SemiBold" Foreground="#333" Margin="0,0,0,20" HorizontalAlignment="Center" /><!-- 进度条 --><ProgressBar x:Name="progressBar"Height="20"Minimum="0"Maximum="100"Value="0"Style="{StaticResource ModernProgressBar}" /><TextBlock x:Name="progressText" FontSize="14" Foreground="#555" HorizontalAlignment="Center" Margin="0,10,0,0" Text="0%" /><Button Content="开始处理"Width="120" Height="36"Background="#0078D7"Foreground="White"FontWeight="Bold"BorderThickness="0"Cursor="Hand"Margin="0,20,0,0"Click="StartProcessing_Click"HorizontalAlignment="Center" /></StackPanel></Grid>
</Window>

二、

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.Shapes;namespace WpfApp.Windows
{/// <summary>/// ProgressWindow.xaml 的交互逻辑/// </summary>public partial class ProgressWindow : Window{public ProgressWindow(){InitializeComponent();}private async void StartProcessing_Click(object sender, RoutedEventArgs e){progressBar.Value = 0;for (int i = 0; i <= 100; i++){progressBar.Value = i;progressText.Text = $"{i}%";await Task.Delay(20);}MessageBox.Show("处理完成!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);}}
}

 

http://www.sczhlp.com/news/1055/

相关文章:

  • P1896 [SCOI2005] 互不侵犯
  • P1879 [USACO06NOV] Corn Fields G
  • P1270 “访问”美术馆
  • 20250726模拟赛T1
  • element plus table 修改勾选中的背景颜色
  • Java使用直接内存的好处
  • Jenkins Pipeline 中的主要组件解释
  • 在powershell窗口执行npm install无法运行
  • SVC总结与思考
  • 国产高精度芯片LHA8961,代替AD7690
  • 【IEEE出版、往届均完成EI检索】第六届计算机视觉与数据挖掘国际学术会议(ICCVDM 2025)
  • 平衡树的一些记录和带插入区间K小值
  • 基于块匹配的全景图像拼接
  • 【ACM独立出版、EI快速稳定检索】第二届虚拟现实、图像和信号处理国际学术会议(VRISP 2025)
  • BMP图像原理与应用
  • 亚马逊AI模型评估产品评论中的实用建议有效性
  • DNS协议
  • Python数据结构(列表、字典、元祖)
  • C#调用邮箱应用发送带附件的邮件
  • Air780EGH定位开发速成指南:源代码公开,即学即用
  • Splunk Enterprise 10.0.0 发布,新增功能简介
  • Studio 3T 2025.13 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
  • 《刚刚问世》系列初窥篇-Java+Playwright自动化测试-24- 操作Select下拉选择框 - 上篇(详细教程) - 北京
  • delphi7 中文企业版编译minipad2
  • 【PCIE725-1 】基于 PCIe x16 总线架构的 JFM9VU9P FPGA 高性能数据预处理平台(100%国产化)
  • Prometheus源码专题【左扬精讲】—— 监控系统 Prometheus 3.4.0 源码解析:Discovery 动态服务发现机制
  • 在运维工作中,Docker的运行状态有哪些?
  • BZOJ 4641 题解
  • APP UI自动化元素定位高频问题
  • 通义灵码保姆级教程:从数据读取、清洗、结合大模型分析、可视化、生成报告全链路