明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 311|回复: 7

WPF弄一个进度条

  [复制链接]
发表于 昨天 09:48 | 显示全部楼层 |阅读模式
CAD自带的进度条不够酷炫,这个可以给你灵感
  1. 前端:
  2. <Window x:Class="HTJ.Views.ProgressView"
  3.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5.         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6.         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7.         xmlns:local="clr-namespace:HTJ.Views"
  8.         mc:Ignorable="d"
  9.         Title="处理进度"
  10.         Height="200"
  11.         Width="500"
  12.         WindowStyle="None"
  13.         AllowsTransparency="True"
  14.         Background="Transparent"
  15.         WindowStartupLocation="CenterScreen"
  16.         Topmost="True" >
  17.     <Window.Resources>
  18.         <!-- 渐变画笔 -->
  19.         <LinearGradientBrush x:Key="PrimaryGradient" StartPoint="0,0" EndPoint="1,1">
  20.             <GradientStop Color="#667eea" Offset="0"/>
  21.             <GradientStop Color="#764ba2" Offset="1"/>
  22.         </LinearGradientBrush>
  23.         
  24.         <LinearGradientBrush x:Key="ProgressGradient" StartPoint="0,0" EndPoint="1,0">
  25.             <GradientStop Color="#f093fb" Offset="0"/>
  26.             <GradientStop Color="#f5576c" Offset="1"/>
  27.         </LinearGradientBrush>

  28.         <!-- 阴影效果 -->
  29.         <DropShadowEffect x:Key="ShadowEffect"
  30.                          ShadowDepth="0"
  31.                          BlurRadius="20"
  32.                          Color="#40000000"
  33.                          Opacity="0.6"/>
  34.         
  35.         <!-- 动画 -->
  36.         <Storyboard x:Key="PulseAnimation" RepeatBehavior="Forever">
  37.             <DoubleAnimation Storyboard.TargetProperty="Opacity"
  38.                            From="0.7" To="1.0" Duration="0:0:1"
  39.                            AutoReverse="True"/>
  40.         </Storyboard>
  41.         
  42.         <Storyboard x:Key="SlideInAnimation">
  43.             <ThicknessAnimation Storyboard.TargetProperty="Margin"
  44.                               From="0,-50,0,0" To="0,0,0,0"
  45.                               Duration="0:0:0.5"
  46.                               DecelerationRatio="0.7"/>
  47.             <DoubleAnimation Storyboard.TargetProperty="Opacity"
  48.                            From="0" To="1" Duration="0:0:0.3"/>
  49.         </Storyboard>

  50.         <!-- 进度条光泽效果 -->
  51.         <LinearGradientBrush x:Key="ProgressGlowBrush" StartPoint="0,0" EndPoint="0,1">
  52.             <GradientStop Color="#80FFFFFF" Offset="0.0"/>
  53.             <GradientStop Color="#00FFFFFF" Offset="0.3"/>
  54.             <GradientStop Color="#00FFFFFF" Offset="0.7"/>
  55.             <GradientStop Color="#40FFFFFF" Offset="1.0"/>
  56.         </LinearGradientBrush>
  57.     </Window.Resources>
  58.    
  59.     <!-- 窗口级别的事件触发器 -->
  60.     <Window.Triggers>
  61.         <EventTrigger RoutedEvent="Window.Loaded">
  62.             <BeginStoryboard Storyboard="{StaticResource SlideInAnimation}"/>
  63.         </EventTrigger>
  64.     </Window.Triggers>
  65.    
  66.     <!-- 主容器 -->
  67.     <Border Background="{StaticResource PrimaryGradient}"
  68.             CornerRadius="15"
  69.             Margin="10"
  70.             Effect="{StaticResource ShadowEffect}">
  71.         
  72.         <Grid Margin="20">
  73.             <Grid.RowDefinitions>
  74.                 <RowDefinition Height="Auto"/>
  75.                 <RowDefinition Height="*"/>
  76.                 <RowDefinition Height="Auto"/>
  77.                 <RowDefinition Height="Auto"/>
  78.             </Grid.RowDefinitions>
  79.             
  80.             <!-- 标题栏 -->
  81.             <Grid Grid.Row="0">
  82.                 <Grid.ColumnDefinitions>
  83.                     <ColumnDefinition Width="*"/>
  84.                     <ColumnDefinition Width="Auto"/>
  85.                 </Grid.ColumnDefinitions>
  86.                
  87.                 <TextBlock Text="图层处理进度"
  88.                          FontSize="16"
  89.                          FontWeight="Bold"
  90.                          Foreground="White"
  91.                          VerticalAlignment="Center"/>
  92.                
  93.                 <!-- 关闭按钮 -->
  94.                 <Button x:Name="BtnClose"
  95.                         Grid.Column="1"
  96.                         Content="&#10005;"
  97.                         Width="25"
  98.                         Height="25"
  99.                         Background="Transparent"
  100.                         BorderBrush="Transparent"
  101.                         Foreground="White"
  102.                         FontSize="12"
  103.                         FontWeight="Bold"
  104.                         Click="btnClose_Click"
  105.                         Cursor="Hand">
  106.                     <Button.Style>
  107.                         <Style TargetType="Button">
  108.                             <Setter Property="Opacity" Value="0.7"/>
  109.                             <Style.Triggers>
  110.                                 <Trigger Property="IsMouseOver" Value="True">
  111.                                     <Setter Property="Opacity" Value="1"/>
  112.                                     <Setter Property="Background" Value="#20FFFFFF"/>
  113.                                 </Trigger>
  114.                             </Style.Triggers>
  115.                         </Style>
  116.                     </Button.Style>
  117.                 </Button>
  118.             </Grid>
  119.             
  120.             <!-- 当前任务 -->
  121.             <TextBlock x:Name="TxtCurrentTask"
  122.                      Grid.Row="1"
  123.                      Text="正在初始化..."
  124.                      FontSize="12"
  125.                      Foreground="#E0FFFFFF"
  126.                      Margin="0,10,0,5"
  127.                      TextWrapping="Wrap"/>
  128.             
  129.             <!-- 进度条区域 -->
  130.             <Border Grid.Row="2"
  131.                     Background="#20FFFFFF"
  132.                     CornerRadius="10"
  133.                     Height="20"
  134.                     Margin="0,5,0,0">
  135.                
  136.                 <!-- 进度条背景 -->
  137.                 <Grid>
  138.                     <!-- 进度条填充 -->
  139.                     <Border x:Name="ProgressBar"
  140.                             HorizontalAlignment="Left"
  141.                             Background="{StaticResource ProgressGradient}"
  142.                             CornerRadius="8"
  143.                             Width="0"
  144.                             Height="16"
  145.                             Margin="2">
  146.                         
  147.                         <!-- 进度条光泽效果 -->
  148.                         <Border Background="{StaticResource ProgressGlowBrush}"
  149.                                 CornerRadius="8"/>
  150.                     </Border>
  151.                 </Grid>
  152.             </Border>
  153.             
  154.             <!-- 进度文本和时间 -->
  155.             <Grid Grid.Row="3" Margin="0,10,0,0">
  156.                 <Grid.ColumnDefinitions>
  157.                     <ColumnDefinition Width="*"/>
  158.                     <ColumnDefinition Width="Auto"/>
  159.                 </Grid.ColumnDefinitions>
  160.                
  161.                 <TextBlock x:Name="TxtProgress"
  162.                          Text="0%"
  163.                          FontSize="11"
  164.                          Foreground="White"
  165.                          FontWeight="SemiBold"/>
  166.                
  167.                 <TextBlock x:Name="TxtTimeRemaining"
  168.                          Grid.Column="1"
  169.                          Text="预计剩余: --"
  170.                          FontSize="10"
  171.                          Foreground="#C0FFFFFF"/>
  172.             </Grid>
  173.         </Grid>
  174.     </Border>
  175. </Window>


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 2明经币 +2 收起 理由
zhoupeng220 + 1 很给力!
zxw2735 + 1 赞一个!

查看全部评分

回复

使用道具 举报

发表于 昨天 11:15 | 显示全部楼层
可以。很漂亮!!!
回复 支持 反对

使用道具 举报

发表于 昨天 11:25 | 显示全部楼层
相当可以,wpf刚开始学,做出来的空间都很丑
回复 支持 反对

使用道具 举报

发表于 昨天 11:33 | 显示全部楼层
哇塞 很炫酷
回复 支持 反对

使用道具 举报

发表于 昨天 17:01 | 显示全部楼层
太酷啦 相 当 哇 塞
回复 支持 反对

使用道具 举报

发表于 昨天 18:38 | 显示全部楼层
本帖最后由 yanshengjiang 于 2025-10-17 18:53 编辑

漂亮,可以被lsp调用吗
回复 支持 反对

使用道具 举报

发表于 昨天 20:16 | 显示全部楼层
驱动文件也发一下,就可以愉快的玩耍了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-10-18 06:20 , Processed in 0.185583 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表