improve:UI

This commit is contained in:
2026-05-01 01:52:36 +08:00
parent ac399773d0
commit 8c2fc15d81
2 changed files with 161 additions and 199 deletions
@@ -6,7 +6,6 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
namespace Ink_Canvas
@@ -18,7 +17,7 @@ namespace Ink_Canvas
public PrivacyAgreementWindow()
{
InitializeComponent();
this.Topmost = true;
Topmost = true;
AnimationsHelper.ShowWithSlideFromBottomAndFade(this, 0.25);
ApplyTheme();
}
@@ -27,13 +26,13 @@ namespace Ink_Canvas
{
try
{
this.Topmost = true;
Topmost = true;
Dispatcher.BeginInvoke(new Action(() =>
{
this.Activate();
this.Focus();
this.Topmost = true;
Activate();
Focus();
Topmost = true;
SetForegroundWindow(new WindowInteropHelper(this).Handle);
}), DispatcherPriority.Loaded);
@@ -76,9 +75,7 @@ namespace Ink_Canvas
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private void Window_Closing(object sender, CancelEventArgs e)
{
}
private void Window_Closing(object sender, CancelEventArgs e) { }
private void ButtonCancel_Click(object sender, RoutedEventArgs e)
{
@@ -98,10 +95,19 @@ namespace Ink_Canvas
{
try
{
if (MainWindow.Settings != null)
var settings = MainWindow.Settings;
if (settings == null) return;
iNKORE.UI.WPF.Modern.ElementTheme target;
switch (settings.Appearance.Theme)
{
ApplyTheme(MainWindow.Settings);
case 0: target = iNKORE.UI.WPF.Modern.ElementTheme.Light; break;
case 1: target = iNKORE.UI.WPF.Modern.ElementTheme.Dark; break;
default: target = IsSystemThemeLight()
? iNKORE.UI.WPF.Modern.ElementTheme.Light
: iNKORE.UI.WPF.Modern.ElementTheme.Dark; break;
}
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, target);
}
catch (Exception ex)
{
@@ -109,97 +115,19 @@ namespace Ink_Canvas
}
}
private void ApplyTheme(Settings settings)
private static bool IsSystemThemeLight()
{
try
{
if (settings.Appearance.Theme == 0)
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Light);
ApplyThemeResources("Light");
}
else if (settings.Appearance.Theme == 1)
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Dark);
ApplyThemeResources("Dark");
}
else
{
bool isSystemLight = IsSystemThemeLight();
if (isSystemLight)
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Light);
ApplyThemeResources("Light");
}
else
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Dark);
ApplyThemeResources("Dark");
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用隐私说明窗口主题出错: {ex.Message}", LogHelper.LogType.Error);
}
}
private void ApplyThemeResources(string theme)
{
try
{
var resources = this.Resources;
if (theme == "Light")
{
resources["PrivacyAgreementWindowBackground"] = new SolidColorBrush(Color.FromRgb(255, 255, 255));
resources["PrivacyAgreementWindowForeground"] = new SolidColorBrush(Color.FromRgb(24, 24, 27));
resources["PrivacyAgreementWindowButtonBackground"] = new SolidColorBrush(Color.FromRgb(244, 244, 245));
resources["PrivacyAgreementWindowButtonForeground"] = new SolidColorBrush(Color.FromRgb(24, 24, 27));
resources["PrivacyAgreementWindowBorderBrush"] = new SolidColorBrush(Color.FromRgb(228, 228, 231));
resources["PrivacyAgreementWindowButtonAcceptBackground"] = new SolidColorBrush(Color.FromRgb(53, 132, 228));
resources["PrivacyAgreementWindowButtonAcceptForeground"] = new SolidColorBrush(Colors.White);
}
else
{
resources["PrivacyAgreementWindowBackground"] = new SolidColorBrush(Color.FromRgb(31, 31, 31));
resources["PrivacyAgreementWindowForeground"] = new SolidColorBrush(Colors.White);
resources["PrivacyAgreementWindowButtonBackground"] = new SolidColorBrush(Color.FromRgb(42, 42, 42));
resources["PrivacyAgreementWindowButtonForeground"] = new SolidColorBrush(Colors.White);
resources["PrivacyAgreementWindowBorderBrush"] = new SolidColorBrush(Color.FromRgb(224, 224, 224));
resources["PrivacyAgreementWindowButtonAcceptBackground"] = new SolidColorBrush(Color.FromRgb(53, 132, 228));
resources["PrivacyAgreementWindowButtonAcceptForeground"] = new SolidColorBrush(Colors.White);
}
}
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)
using (var themeKey = registryKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"))
{
var value = themeKey.GetValue("AppsUseLightTheme");
if (value != null)
{
light = (int)value == 1;
}
themeKey.Close();
var value = themeKey?.GetValue("AppsUseLightTheme");
if (value is int i) return i == 1;
}
}
catch
{
light = true;
}
return light;
catch { }
return true;
}
}
}
}