Improve focus handling and window initialization

Added `IsTabStop="True"` to `RootGrid` in `MainWindow.xaml` to make it focusable. Updated `DispatcherQueue.TryEnqueue` in `MainWindow.xaml.cs` to clear focus from interactive elements (e.g., sliders) on window open, preventing unwanted tooltips and ensuring a cleaner initial state.
This commit is contained in:
Yu Leng
2025-11-28 00:15:00 +08:00
parent 1f425f9540
commit a4e2fe18fe
2 changed files with 9 additions and 2 deletions

View File

@@ -21,7 +21,7 @@
<DesktopAcrylicBackdrop /> <DesktopAcrylicBackdrop />
</winuiex:WindowEx.SystemBackdrop> </winuiex:WindowEx.SystemBackdrop>
<Grid x:Name="RootGrid"> <Grid x:Name="RootGrid" IsTabStop="True">
<Grid.Resources> <Grid.Resources>
<Style <Style
x:Key="FlyoutButtonStyle" x:Key="FlyoutButtonStyle"

View File

@@ -219,7 +219,14 @@ namespace PowerDisplay
// This is critical because the OS might restore the window to a previous (incorrect) size // This is critical because the OS might restore the window to a previous (incorrect) size
// when ShowWindow is called, ignoring our pre-show adjustment. // when ShowWindow is called, ignoring our pre-show adjustment.
// By queuing this on the dispatcher, we ensure it runs after the window is visible and layout is active. // By queuing this on the dispatcher, we ensure it runs after the window is visible and layout is active.
DispatcherQueue.TryEnqueue(() => AdjustWindowSizeToContent()); DispatcherQueue.TryEnqueue(() =>
{
AdjustWindowSizeToContent();
// Clear focus from any interactive element (e.g., Slider) to prevent
// showing the value tooltip when the window opens
RootGrid.Focus(FocusState.Programmatic);
});
bool isVisible = IsWindowVisible(); bool isVisible = IsWindowVisible();
if (!isVisible) if (!isVisible)