From 8c2fc15d81c52df7cc8e0b0baec8027fb6edee2f Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Fri, 1 May 2026 01:52:36 +0800 Subject: [PATCH] improve:UI --- .../Windows/PrivacyAgreementWindow.xaml | 240 ++++++++++-------- .../Windows/PrivacyAgreementWindow.xaml.cs | 120 ++------- 2 files changed, 161 insertions(+), 199 deletions(-) diff --git a/Ink Canvas/Windows/PrivacyAgreementWindow.xaml b/Ink Canvas/Windows/PrivacyAgreementWindow.xaml index 8d11a402..9c7cd2dd 100644 --- a/Ink Canvas/Windows/PrivacyAgreementWindow.xaml +++ b/Ink Canvas/Windows/PrivacyAgreementWindow.xaml @@ -3,130 +3,164 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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" xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf" + xmlns:sys="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" - FontFamily="Microsoft YaHei UI" + Title="隐私说明 - InkCanvasForClass" + Height="640" Width="720" + MinHeight="420" MinWidth="520" WindowStartupLocation="CenterScreen" Topmost="True" - Title="隐私说明 - Ink Canvas" Height="600" Width="600" ui:ThemeManager.IsThemeAware="True" ui:TitleBar.ExtendViewIntoTitleBar="True" ui:WindowHelper.SystemBackdropType="Mica" ui:WindowHelper.UseModernWindowStyle="True" ui:TitleBar.Height="48" Loaded="Window_Loaded" Closing="Window_Closing"> + - - - - - - - + + + + + + + + - - + + + + - - - + + + + + + + + + + + + + + + + + - - - + + + + + + - + + + - - - - - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Ink Canvas/Windows/PrivacyAgreementWindow.xaml.cs b/Ink Canvas/Windows/PrivacyAgreementWindow.xaml.cs index ad22c4f2..1c4274c9 100644 --- a/Ink Canvas/Windows/PrivacyAgreementWindow.xaml.cs +++ b/Ink Canvas/Windows/PrivacyAgreementWindow.xaml.cs @@ -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; } } -} - +} \ No newline at end of file