diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 9cb41455..79993a88 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -2026,8 +2026,49 @@ namespace Ink_Canvas MessageBox.Show("快捷键管理器尚未初始化,请稍后重试。", "错误", MessageBoxButton.OK, MessageBoxImage.Error); return; } + + // 创建快捷键设置窗口 var hotkeySettingsWindow = new HotkeySettingsWindow(this, _globalHotkeyManager); - hotkeySettingsWindow.Owner = this; + + // 确保窗口在显示前获得正确的焦点和置顶状态 + hotkeySettingsWindow.Loaded += (s, e) => + { + try + { + // 确保窗口获得焦点 + hotkeySettingsWindow.Activate(); + hotkeySettingsWindow.Focus(); + + // 如果主窗口处于置顶状态,临时调整子窗口的置顶状态 + if (Settings.Advanced.IsAlwaysOnTop) + { + // 临时设置子窗口为置顶,确保它在主窗口之上 + hotkeySettingsWindow.Topmost = true; + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"设置快捷键设置窗口焦点时出错: {ex.Message}", LogHelper.LogType.Error); + } + }; + + // 窗口关闭时恢复置顶状态 + hotkeySettingsWindow.Closed += (s, e) => + { + try + { + // 恢复主窗口的置顶状态 + if (Settings.Advanced.IsAlwaysOnTop) + { + ApplyAlwaysOnTop(); + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"恢复主窗口置顶状态时出错: {ex.Message}", LogHelper.LogType.Error); + } + }; + hotkeySettingsWindow.ShowDialog(); } catch (Exception ex) diff --git a/Ink Canvas/Windows/HotkeySettingsWindow.xaml b/Ink Canvas/Windows/HotkeySettingsWindow.xaml index 6c89c1f8..e6f41019 100644 --- a/Ink Canvas/Windows/HotkeySettingsWindow.xaml +++ b/Ink Canvas/Windows/HotkeySettingsWindow.xaml @@ -6,7 +6,6 @@ xmlns:local="clr-namespace:Ink_Canvas.Windows" xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" ui:ThemeManager.RequestedTheme="Light" - Topmost="True" Background="Transparent" AllowsTransparency="True" mc:Ignorable="d" diff --git a/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs b/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs index f185d211..bf24f0c0 100644 --- a/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs +++ b/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs @@ -27,6 +27,9 @@ namespace Ink_Canvas.Windows _hotkeyManager = hotkeyManager; _hotkeyItems = new Dictionary(); + // 设置窗口属性以避免与主窗口置顶维护冲突 + SetupWindowProperties(); + // 隐藏主窗口的设置页面 HideMainWindowSettings(); InitializeHotkeyItems(); @@ -58,6 +61,31 @@ namespace Ink_Canvas.Windows #endregion #region Private Methods + /// + /// 设置窗口属性以避免与主窗口置顶维护冲突 + /// + private void SetupWindowProperties() + { + try + { + // 设置为模态窗口,确保它始终在主窗口之上 + // 但不设置Topmost,避免与主窗口的置顶维护机制冲突 + this.Owner = _mainWindow; + + // 设置窗口启动位置为屏幕中心 + this.WindowStartupLocation = WindowStartupLocation.CenterScreen; + + // 确保窗口在显示时获得焦点 + this.ShowInTaskbar = false; + + LogHelper.WriteLogToFile("快捷键设置窗口属性已设置"); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"设置快捷键设置窗口属性时出错: {ex.Message}", LogHelper.LogType.Error); + } + } + private void InitializeHotkeyItems() { try @@ -562,8 +590,20 @@ namespace Ink_Canvas.Windows /// private void HotkeySettingsWindow_Closed(object sender, EventArgs e) { - // 恢复主窗口设置页面的显示 - ShowMainWindowSettings(); + try + { + // 重置窗口置顶状态,避免影响主窗口 + this.Topmost = false; + + // 恢复主窗口设置页面的显示 + ShowMainWindowSettings(); + + LogHelper.WriteLogToFile("快捷键设置窗口已关闭,置顶状态已重置"); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"快捷键设置窗口关闭时出错: {ex.Message}", LogHelper.LogType.Error); + } } #endregion