improve:主题切换

This commit is contained in:
2025-10-04 22:59:11 +08:00
parent efcc01ad6b
commit 5bebf077e4
3 changed files with 61 additions and 18 deletions
@@ -5,18 +5,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Ink_Canvas"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
ui:ThemeManager.RequestedTheme="Light" Topmost="True" Background="Transparent"
Topmost="True" Background="Transparent"
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True"
Loaded="Window_Loaded" Closing="Window_Closing" WindowStartupLocation="CenterScreen"
Title="Ink Canvas 画板 - 计时器" Height="400" Width="600">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Resources/Styles/Light.xaml"/>
<ResourceDictionary Source="../Resources/Styles/Dark.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Border Background="{DynamicResource SeewoTimerWindowBackground}" CornerRadius="15" BorderThickness="1" BorderBrush="{DynamicResource SeewoTimerWindowBorderBrush}" Margin="10">
<Grid>
<!-- 主要内容区域 -->
@@ -91,16 +91,10 @@ namespace Ink_Canvas
{
try
{
// 根据主题设置数字显示颜色
var digitForeground = Application.Current.FindResource("SeewoTimerWindowDigitForeground") as SolidColorBrush;
if (digitForeground != null)
// 应用主题设置
if (MainWindow.Settings != null)
{
Digit1Display.Foreground = digitForeground;
Digit2Display.Foreground = digitForeground;
Digit3Display.Foreground = digitForeground;
Digit4Display.Foreground = digitForeground;
Digit5Display.Foreground = digitForeground;
Digit6Display.Foreground = digitForeground;
ApplyTheme(MainWindow.Settings);
}
}
catch (Exception ex)
@@ -109,6 +103,62 @@ namespace Ink_Canvas
}
}
private void ApplyTheme(Settings settings)
{
try
{
if (settings.Appearance.Theme == 0) // 浅色主题
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Light);
}
else if (settings.Appearance.Theme == 1) // 深色主题
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Dark);
}
else // 跟随系统主题
{
bool isSystemLight = IsSystemThemeLight();
if (isSystemLight)
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Light);
}
else
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Dark);
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用仿希沃倒计时窗口主题出错: {ex.Message}", LogHelper.LogType.Error);
}
}
private bool IsSystemThemeLight()
{
var light = false;
try
{
var registryKey = Microsoft.Win32.Registry.CurrentUser;
var themeKey = registryKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
if (themeKey != null)
{
var value = themeKey.GetValue("AppsUseLightTheme");
if (value != null)
{
light = (int)value == 1;
}
themeKey.Close();
}
}
catch
{
// 如果读取注册表失败,默认为浅色主题
light = true;
}
return light;
}
private void UpdateDigitDisplays()
{
Digit1Display.Text = (hour / 10).ToString();