From 4724a432abf37ad5dcb253278180178ba9038ae1 Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Wed, 1 Oct 2025 23:26:38 +0800 Subject: [PATCH] =?UTF-8?q?add:=E8=BD=AF=E4=BB=B6=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Windows/SplashScreen.xaml | 57 ++++++++++--------------- Ink Canvas/Windows/SplashScreen.xaml.cs | 38 ++++++++++++----- 2 files changed, 49 insertions(+), 46 deletions(-) diff --git a/Ink Canvas/Windows/SplashScreen.xaml b/Ink Canvas/Windows/SplashScreen.xaml index 4949f84a..268dfed3 100644 --- a/Ink Canvas/Windows/SplashScreen.xaml +++ b/Ink Canvas/Windows/SplashScreen.xaml @@ -13,16 +13,17 @@ - + - + - + - + - - - - - + + + + + + + diff --git a/Ink Canvas/Windows/SplashScreen.xaml.cs b/Ink Canvas/Windows/SplashScreen.xaml.cs index 8af10ab9..593986cb 100644 --- a/Ink Canvas/Windows/SplashScreen.xaml.cs +++ b/Ink Canvas/Windows/SplashScreen.xaml.cs @@ -95,29 +95,45 @@ namespace Ink_Canvas.Windows { Dispatcher.Invoke(() => { - if (LoadingProgress.IsIndeterminate) + // 获取进度条容器的实际宽度 + double containerWidth = ProgressBarBackground.ActualWidth; + if (containerWidth <= 0) { - LoadingProgress.IsIndeterminate = false; - LoadingProgress.Value = 0; + // 如果ActualWidth为0,使用设计时宽度 + containerWidth = 530; } - // 创建平滑过渡动画 - var animation = new DoubleAnimation + // 计算目标宽度 + double targetWidth = containerWidth * (progress / 100.0); + + // 创建Storyboard动画 + var storyboard = new Storyboard(); + + // 创建宽度动画 + var widthAnimation = new DoubleAnimation { - From = LoadingProgress.Value, - To = progress, - Duration = TimeSpan.FromMilliseconds(300), + From = ProgressBarFill.Width, + To = targetWidth, + Duration = TimeSpan.FromMilliseconds(300), EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut } }; + // 设置动画目标 + Storyboard.SetTarget(widthAnimation, ProgressBarFill); + Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(Border.WidthProperty)); + + // 添加动画到Storyboard + storyboard.Children.Add(widthAnimation); + // 添加动画完成事件 - animation.Completed += (s, e) => + storyboard.Completed += (s, e) => { // 确保最终值正确设置 - LoadingProgress.Value = progress; + ProgressBarFill.Width = targetWidth; }; - LoadingProgress.BeginAnimation(ProgressBar.ValueProperty, animation); + // 开始动画 + storyboard.Begin(); }); }