add:软件启动动画

This commit is contained in:
2025-10-01 18:17:39 +08:00
parent 583f47c98b
commit aed77a187f
6 changed files with 290 additions and 2 deletions
+57
View File
@@ -0,0 +1,57 @@
<Window x:Class="Ink_Canvas.Windows.SplashScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Ink Canvas"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
WindowState="Maximized"
Topmost="True"
ShowInTaskbar="False"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen">
<Grid>
<!-- 背景遮罩 -->
<Rectangle Fill="#80000000" />
<!-- 启动图片容器 -->
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel>
<!-- 启动图片 -->
<Image x:Name="StartupImage"
Source="pack://application:,,,/Resources/ICC Start.png"
Width="600"
Height="450"
Stretch="Uniform" />
<!-- 版本号显示 - 右上角 -->
<TextBlock x:Name="VersionTextBlock"
FontSize="12"
Foreground="FloralWhite"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,-385,50,0"
Opacity="0.8"
Panel.ZIndex="1000" />
<!-- 加载文本 -->
<TextBlock x:Name="LoadingText"
Text="正在启动 Ink Canvas..."
FontSize="18"
FontWeight="SemiBold"
Foreground="White"
HorizontalAlignment="Center"
Margin="0,-150,0,0" />
<!-- 进度条 -->
<ProgressBar x:Name="LoadingProgress"
Width="500"
Height="8"
Margin="0,-170,0,0"
Background="#40000000"
Foreground="#0078D4"
IsIndeterminate="True" />
</StackPanel>
</Grid>
</Grid>
</Window>
+134
View File
@@ -0,0 +1,134 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Threading;
namespace Ink_Canvas.Windows
{
/// <summary>
/// SplashScreen.xaml 的交互逻辑
/// </summary>
public partial class SplashScreen : Window
{
private DispatcherTimer _timer;
private int _loadingStep = 0;
private readonly string[] _loadingMessages = {
"正在启动 Ink Canvas...",
"正在初始化组件...",
"正在加载配置...",
"正在准备界面...",
"启动完成!"
};
public SplashScreen()
{
InitializeComponent();
InitializeSplashScreen();
}
private void InitializeSplashScreen()
{
// 设置窗口居中
WindowStartupLocation = WindowStartupLocation.CenterScreen;
// 设置版本号
SetVersionText();
// 启动加载动画
StartLoadingAnimation();
}
private void StartLoadingAnimation()
{
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(1200)
};
_timer.Tick += Timer_Tick;
_timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
if (_loadingStep < _loadingMessages.Length)
{
LoadingText.Text = _loadingMessages[_loadingStep];
_loadingStep++;
}
else
{
_timer.Stop();
// 不要自动关闭启动画面,等待外部调用CloseSplashScreen
}
}
public void CloseSplashScreen()
{
// 添加淡出动画
var fadeOutAnimation = new DoubleAnimation
{
From = 1,
To = 0,
Duration = TimeSpan.FromMilliseconds(300),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
fadeOutAnimation.Completed += (s, e) =>
{
this.Close();
};
this.BeginAnimation(OpacityProperty, fadeOutAnimation);
}
/// <summary>
/// 设置加载进度(0-100
/// </summary>
/// <param name="progress">进度百分比</param>
public void SetProgress(int progress)
{
Dispatcher.Invoke(() =>
{
LoadingProgress.IsIndeterminate = false;
LoadingProgress.Value = progress;
});
}
/// <summary>
/// 设置加载消息
/// </summary>
/// <param name="message">加载消息</param>
public void SetLoadingMessage(string message)
{
Dispatcher.Invoke(() =>
{
LoadingText.Text = message;
});
}
/// <summary>
/// 设置版本号文本
/// </summary>
private void SetVersionText()
{
try
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
if (version != null)
{
VersionTextBlock.Text = $"v{version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
}
else
{
VersionTextBlock.Text = "v5.0.4.0";
}
}
catch
{
VersionTextBlock.Text = "v5.0.4.0";
}
}
}
}