本帖最后由 wang2006zhi 于 2025-10-23 00:04 编辑
前端
复制代码前端关联
数据
业务逻辑复制代码调用网友答:
可以。很漂亮!!!网友答:
相当可以,wpf刚开始学,做出来的空间都很丑网友答:
哇塞 很炫酷网友答:
相 当 哇 塞网友答:
本帖最后由 yanshengjiang 于 2025-10-17 18:53 编辑
漂亮,可以被lsp调用吗网友答: 驱动文件也发一下,就可以愉快的玩耍了。网友答: 一看就是热爱生活的
网友答:
干看见很哇塞,不会用

- <Window x:Class="HTJ.Views.ProgressView"
- 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:vm="clr-namespace:HTJ.ViewModels"
- mc:Ignorable="d"
- Height="200"
- Width="500"
- WindowStyle="None"
- AllowsTransparency="True"
- Background="Transparent"
- WindowStartupLocation="CenterScreen"
- Topmost="True" >
- <Window.Resources>
- <!-- 渐变画笔 -->
- <LinearGradientBrush x:Key="PrimaryGradient" StartPoint="0,0" EndPoint="1,1">
- <GradientStop Color="#667eea" Offset="0"/>
- <GradientStop Color="#764ba2" Offset="1"/>
- </LinearGradientBrush>
- <LinearGradientBrush x:Key="ProgressGradient" StartPoint="0,0" EndPoint="1,0">
- <GradientStop Color="#f093fb" Offset="0"/>
- <GradientStop Color="#f5576c" Offset="1"/>
- </LinearGradientBrush>
- <!-- 阴影效果 -->
- <DropShadowEffect x:Key="ShadowEffect" ShadowDepth="0" BlurRadius="20" Color="#40000000" Opacity="0.6"/>
-
- <!-- 进度条光泽效果 -->
- <LinearGradientBrush x:Key="ProgressGlowBrush" StartPoint="0,0" EndPoint="0,1">
- <GradientStop Color="#80FFFFFF" Offset="0.0"/>
- <GradientStop Color="#00FFFFFF" Offset="0.3"/>
- <GradientStop Color="#00FFFFFF" Offset="0.7"/>
- <GradientStop Color="#40FFFFFF" Offset="1.0"/>
- </LinearGradientBrush>
- </Window.Resources>
- <Window.DataContext>
- <vm:ProgressViewModel />
- </Window.DataContext>
- <Border Margin="20" Background="{StaticResource PrimaryGradient}"
- CornerRadius="15"
- Effect="{StaticResource ShadowEffect}">
- <Grid Margin="20">
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="Auto"/>
- </Grid.RowDefinitions>
-
- <!-- 标题栏 -->
- <Grid Grid.Row="0">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="Auto"/>
- </Grid.ColumnDefinitions>
-
- <!-- 标题-->
- <TextBlock Text="{Binding VmData.Title}"
- FontSize="16"
- FontWeight="Bold"
- Foreground="White"
- VerticalAlignment="Center"/>
-
- <!-- 按钮-->
- <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center" >
- <Button Content="开始" Command="{Binding StartCommand}" />
- <Button Content="取消" Command="{Binding CancelCommand}" />
- <Button Content="重置" Command="{Binding ResetCommand}" />
- </StackPanel>
- </Grid>
-
- <!-- 当前任务 -->
- <TextBlock Grid.Row="1"
- Text="{Binding VmData.TxtCurrentTask}"
- FontSize="12"
- Foreground="#E0FFFFFF"
- Margin="0,10,0,5"
- TextWrapping="Wrap"/>
-
- <!-- 进度条区域 -->
- <ProgressBar Grid.Row="2"
- Foreground="{StaticResource ProgressGradient}"
- Background="{StaticResource ProgressGlowBrush}"
- Value="{Binding VmData.ProgressValue}"
- Minimum="{Binding VmData.Minimum}"
- Maximum="{Binding VmData.Maximum}"
- Height="20" Margin="0,0,0,10" />
-
- <!-- 进度文本和时间 -->
- <Grid Grid.Row="3" Margin="0,10,0,0">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="Auto"/>
- </Grid.ColumnDefinitions>
- <TextBlock Grid.Column="0"
- Text="{Binding VmData.TxtProgress}"
- FontSize="11"
- Foreground="White"
- FontWeight="SemiBold"/>
- <TextBlock Grid.Column="1"
- Text="{Binding VmData.TxtTimeRemaining}"
- FontSize="11"
- Foreground="#C0FFFFFF"/>
- </Grid>
- </Grid>
- </Border>
- </Window>
- public partial class ProgressView
- {
- public ProgressView()
- {
- InitializeComponent();
- }
- //窗体关闭事件
- protected override void OnClosing(CancelEventArgs e)
- {
- e.Cancel = true;
- Hide();
- }
- }

- using HTJ.Views;
- namespace HTJ.Models;
- [AppHelper.Service]
- public partial class ProgressModel: ObservableObject
- {
- [ObservableProperty] private string _title = "任务处理进度";
-
- [ObservableProperty] private string _txtCurrentTask = "正在初始化..." ;
-
- [ObservableProperty] private string _txtTimeRemaining = "预计剩余: --";
-
- [ObservableProperty] [NotifyPropertyChangedFor(nameof(TxtProgress))]
-
- private double _progressValue;
-
- [ObservableProperty] private int _closeTime = 3000;
-
- [ObservableProperty] private int _minimum;
-
- [ObservableProperty] private int _maximum = 100;
- public string TxtProgress => $"{ProgressValue*100/Maximum:F0}%";
-
- /// <summary>
- /// 启动自动关闭倒计时
- /// </summary>
- public async Task AutoClose()
- {
- var tokenSource = new CancellationTokenSource();
-
- try
- {
- // 更新剩余时间显示为关闭倒计时
- int seconds = CloseTime / 1000;
- for (int i = seconds; i > 0; i--)
- {
- if (tokenSource.Token.IsCancellationRequested)
- break;
- TxtTimeRemaining = $"窗口将在 {i} 秒后自动关闭...";
- await Task.Delay(1000, tokenSource.Token);
- }
- if (!tokenSource.Token.IsCancellationRequested)
- {
- // 关闭窗口
- var view = AppHelper.GetService<ProgressView>();
- view.Hide();
- }
- }
- catch (TaskCanceledException)
- {
- // 自动关闭被取消
- TxtTimeRemaining = "自动关闭已取消";
- }
- }
- }

- using HTJ.Arx.Service.Interface;
- using HTJ.Models;
- using HTJ.Views;
- namespace HTJ.ViewModels;
- public partial class ProgressViewModel: ObservableObject
- {
- private static readonly IUserSetting IuserSetting = AppX.IuserSetting;
- [ObservableProperty] private ProgressModel _vmData = IuserSetting.GetService<ProgressModel>();
-
- private CancellationTokenSource? _cancellationTokenSource;
-
- [RelayCommand]
- private async Task Start()
- {
- _cancellationTokenSource = new CancellationTokenSource();
-
- try
- {
- VmData.TxtCurrentTask = "开始处理...";
- VmData.ProgressValue = 0;
- // 模拟进度更新
- for (int i = 0; i <= VmData.Maximum; i++)
- {
- if (_cancellationTokenSource.Token.IsCancellationRequested)
- break;
- // 添加小的延迟,让UI有机会更新
- await Task.Delay(10, _cancellationTokenSource.Token);
- VmData.ProgressValue = i;
- VmData.TxtCurrentTask = GetTaskDescription(i);
- VmData.TxtTimeRemaining = GetRemainingTime(i);
- }
- if (!_cancellationTokenSource.Token.IsCancellationRequested)
- {
- VmData.TxtCurrentTask = "处理完成!";
- VmData.TxtTimeRemaining = "剩余时间: 0秒";
- await AutoCloseAfterDelay(VmData.CloseTime);
- }
- }
- catch (TaskCanceledException)
- {
- VmData.TxtCurrentTask = "操作已取消";
- VmData.TxtTimeRemaining = "已中断";
- }
- }
-
- [RelayCommand]
- private void Cancel()
- {
- _cancellationTokenSource?.Cancel();
- }
- [RelayCommand]
- private void Reset()
- {
- VmData.ProgressValue = 0;
- VmData.TxtCurrentTask = "正在初始化...";
- VmData.TxtTimeRemaining = "预计剩余: --";
- VmData.ProgressValue = 0;
- }
-
- /// <summary>
- /// 计算当前任务状态
- /// </summary>
- /// <param name="progress"></param>
- /// <returns></returns>
- private string GetTaskDescription(int progress)
- {
- return progress switch
- {
- < 20 => "正在加载图层数据...",
- < 40 => "正在分析图层结构...",
- < 60 => "正在处理图层样式...",
- < 80 => "正在优化图层性能...",
- < 100 => "正在保存处理结果...",
- _ => "处理完成"
- };
- }
-
- /// <summary>
- /// 计算剩余时间
- /// </summary>
- /// <param name="progress"></param>
- /// <returns></returns>
- private string GetRemainingTime(int progress)
- {
- if (progress == 0) return "预计剩余: --";
- var remaining = (VmData.Maximum - progress) * 0.1; // 基于模拟延迟计算
- return $"预计剩余: {remaining:F1}秒";
- }
-
- /// <summary>
- /// 启动自动关闭倒计时
- /// </summary>
- /// <param name="delayMilliseconds">延迟毫秒数</param>
- private async Task AutoCloseAfterDelay(int delayMilliseconds)
- {
- var tokenSource = new CancellationTokenSource();
-
- try
- {
- // 更新剩余时间显示为关闭倒计时
- int seconds = delayMilliseconds / 1000;
- for (int i = seconds; i > 0; i--)
- {
- if (tokenSource.Token.IsCancellationRequested)
- break;
- VmData.TxtTimeRemaining = $"窗口将在 {i} 秒后自动关闭...";
- await Task.Delay(1000, tokenSource.Token);
- }
- if (!tokenSource.Token.IsCancellationRequested)
- {
- // 触发关闭窗口事件
- var view = AppHelper.GetService<ProgressView>();
- view.Hide();
- }
- }
- catch (TaskCanceledException)
- {
- // 自动关闭被取消
- VmData.TxtTimeRemaining = "自动关闭已取消";
- }
- }
-
- }
- [CommandMethod("tt8")]
- public void Tt8()
- {
- var progressModel = AppHelper.GetService<ProgressModel>();
- // 设置进度参数
- progressModel.Title = "图层重命名进度";
- progressModel.CloseTime = 2000;
- progressModel.Maximum = 400;
- progressModel.ProgressValue = 0;
- progressModel.TxtCurrentTask = "开始处理图层重命名...";
- progressModel.TxtTimeRemaining = $"总共 {progressModel.Maximum} 个图层需要处理";
- var view = AppHelper.GetService<ProgressView>();
- view.Show();
-
- }
漂亮,可以被lsp调用吗网友答: 驱动文件也发一下,就可以愉快的玩耍了。网友答: 一看就是热爱生活的
网友答:
干看见很哇塞,不会用