mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-30 17:07:23 +01:00
Compare commits
2 Commits
jay/LightS
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84e5bd1007 | ||
|
|
783301a9d7 |
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.WinUI.Controls;
|
||||
using Microsoft.PowerToys.Settings.UI.Controls;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Hosting;
|
||||
@@ -42,6 +43,13 @@ public abstract partial class NavigatablePage : Page
|
||||
|
||||
private async void OnPageLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// If we have navigation parameters, disable default focus in SettingsPageControl
|
||||
// to allow proper focus management of the target element
|
||||
if (_pendingNavigationParams != null && !string.IsNullOrEmpty(_pendingNavigationParams.ElementName))
|
||||
{
|
||||
SetSettingsPageControlDefaultFocus(false);
|
||||
}
|
||||
|
||||
if (_pendingNavigationParams != null && !string.IsNullOrEmpty(_pendingNavigationParams.ElementName))
|
||||
{
|
||||
// First, expand parent if specified
|
||||
@@ -66,6 +74,12 @@ public abstract partial class NavigatablePage : Page
|
||||
AnimationDesired = true,
|
||||
});
|
||||
|
||||
// Ensure the target element gets focus after bringing it into view
|
||||
if (target is Control targetControl)
|
||||
{
|
||||
targetControl.Focus(FocusState.Programmatic);
|
||||
}
|
||||
|
||||
await OnTargetElementNavigatedAsync(target, _pendingNavigationParams.ElementName);
|
||||
|
||||
_pendingNavigationParams = null;
|
||||
@@ -141,4 +155,35 @@ public abstract partial class NavigatablePage : Page
|
||||
var element = this.FindName(name) as FrameworkElement;
|
||||
return element;
|
||||
}
|
||||
|
||||
private void SetSettingsPageControlDefaultFocus(bool shouldSetDefaultFocus)
|
||||
{
|
||||
// Find any SettingsPageControl in the page and set the focus behavior
|
||||
var settingsPageControl = FindSettingsPageControl(this);
|
||||
if (settingsPageControl != null)
|
||||
{
|
||||
settingsPageControl.ShouldSetDefaultFocus = shouldSetDefaultFocus;
|
||||
}
|
||||
}
|
||||
|
||||
private SettingsPageControl FindSettingsPageControl(DependencyObject parent)
|
||||
{
|
||||
if (parent is SettingsPageControl settingsPageControl)
|
||||
{
|
||||
return settingsPageControl;
|
||||
}
|
||||
|
||||
int childCount = Microsoft.UI.Xaml.Media.VisualTreeHelper.GetChildrenCount(parent);
|
||||
for (int i = 0; i < childCount; i++)
|
||||
{
|
||||
var child = Microsoft.UI.Xaml.Media.VisualTreeHelper.GetChild(parent, i);
|
||||
var result = FindSettingsPageControl(child);
|
||||
if (result != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,12 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
set { SetValue(ModuleContentProperty, value); }
|
||||
}
|
||||
|
||||
public bool ShouldSetDefaultFocus
|
||||
{
|
||||
get { return (bool)GetValue(ShouldSetDefaultFocusProperty); }
|
||||
set { SetValue(ShouldSetDefaultFocusProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ModuleTitleProperty = DependencyProperty.Register(nameof(ModuleTitle), typeof(string), typeof(SettingsPageControl), new PropertyMetadata(defaultValue: null));
|
||||
public static readonly DependencyProperty ModuleDescriptionProperty = DependencyProperty.Register(nameof(ModuleDescription), typeof(string), typeof(SettingsPageControl), new PropertyMetadata(defaultValue: null));
|
||||
public static readonly DependencyProperty ModuleImageSourceProperty = DependencyProperty.Register(nameof(ModuleImageSource), typeof(Uri), typeof(SettingsPageControl), new PropertyMetadata(null));
|
||||
@@ -68,10 +74,15 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
public static readonly DependencyProperty SecondaryLinksHeaderProperty = DependencyProperty.Register(nameof(SecondaryLinksHeader), typeof(string), typeof(SettingsPageControl), new PropertyMetadata(default(string)));
|
||||
public static readonly DependencyProperty SecondaryLinksProperty = DependencyProperty.Register(nameof(SecondaryLinks), typeof(ObservableCollection<PageLink>), typeof(SettingsPageControl), new PropertyMetadata(new ObservableCollection<PageLink>()));
|
||||
public static readonly DependencyProperty ModuleContentProperty = DependencyProperty.Register(nameof(ModuleContent), typeof(object), typeof(SettingsPageControl), new PropertyMetadata(new Grid()));
|
||||
public static readonly DependencyProperty ShouldSetDefaultFocusProperty = DependencyProperty.Register(nameof(ShouldSetDefaultFocus), typeof(bool), typeof(SettingsPageControl), new PropertyMetadata(true));
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PrimaryLinksControl.Focus(FocusState.Programmatic);
|
||||
// Only set default focus if there's no pending navigation (e.g., from search results)
|
||||
if (ShouldSetDefaultFocus)
|
||||
{
|
||||
PrimaryLinksControl.Focus(FocusState.Programmatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user