diff --git a/Ink Canvas/Windows/RandWindow.xaml b/Ink Canvas/Windows/RandWindow.xaml index f73658ac..3abef0c0 100644 --- a/Ink Canvas/Windows/RandWindow.xaml +++ b/Ink Canvas/Windows/RandWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" xmlns:local="clr-namespace:Ink_Canvas" FontFamily="Microsoft YaHei UI" - ui:ThemeManager.RequestedTheme="Light" Topmost="True" Background="Transparent" + Topmost="True" Background="Transparent" mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" Title="Ink Canvas 抽奖" Height="500" Width="900"> diff --git a/Ink Canvas/Windows/RandWindow.xaml.cs b/Ink Canvas/Windows/RandWindow.xaml.cs index dd2aba29..f4b670aa 100644 --- a/Ink Canvas/Windows/RandWindow.xaml.cs +++ b/Ink Canvas/Windows/RandWindow.xaml.cs @@ -82,6 +82,27 @@ namespace Ink_Canvas { 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); + } + } + // 根据主题设置窗口背景 if (settings.RandSettings.SelectedBackgroundIndex <= 0) { @@ -99,6 +120,23 @@ namespace Ink_Canvas } } + private bool IsSystemThemeLight() + { + var light = false; + try + { + var registryKey = Microsoft.Win32.Registry.CurrentUser; + var themeKey = + registryKey.OpenSubKey("software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); + var keyValue = 0; + if (themeKey != null) keyValue = (int)themeKey.GetValue("SystemUsesLightTheme"); + if (keyValue == 1) light = true; + } + catch { } + + return light; + } + public RandWindow(Settings settings, bool IsAutoClose) { InitializeComponent();