improve:主题切换

This commit is contained in:
2025-10-05 09:33:25 +08:00
parent c32eaed534
commit cc054aeb75
5 changed files with 95 additions and 19 deletions
@@ -1,6 +1,8 @@
using Ink_Canvas.Helpers;
using System.Windows;
using System.Windows.Input;
using iNKORE.UI.WPF.Modern;
using System;
namespace Ink_Canvas
{
@@ -43,5 +45,53 @@ namespace Ink_Canvas
{
e.Handled = true;
}
/// <summary>
/// 刷新主题
/// </summary>
public void RefreshTheme()
{
try
{
// 根据当前主题设置窗口主题
bool isDarkTheme = MainWindow.Settings.Appearance.Theme == 1 ||
(MainWindow.Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
if (isDarkTheme)
{
ThemeManager.SetRequestedTheme(this, ElementTheme.Dark);
}
else
{
ThemeManager.SetRequestedTheme(this, ElementTheme.Light);
}
// 强制刷新UI
InvalidateVisual();
}
catch (Exception)
{
}
}
/// <summary>
/// 检查系统主题是否为浅色
/// </summary>
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;
}
}
}