add:软件启动动画

This commit is contained in:
2025-10-01 23:26:38 +08:00
parent 5b9c1627c0
commit 4724a432ab
2 changed files with 49 additions and 46 deletions
+27 -11
View File
@@ -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();
});
}