From 7a47a7fe0e6a7597de34ccc5b13e88889d2c823c Mon Sep 17 00:00:00 2001 From: Reza Bakhshi Laktasaraei <74649066+rezabakhshilaktasaraei@users.noreply.github.com> Date: Sun, 13 Apr 2025 21:31:46 +0330 Subject: [PATCH] Add accessibility name to theme toggle button and helper method for visual tree search - Added MainWindow_Loaded event handler to set the automation name of the theme toggle button to the localized "MoreOptions" string using ServiceLib.Resx.ResUI. - Introduced FindVisualChild helper method to recursively search for a named child element in the visual tree. - Included necessary using directives for System.Windows.Automation and System.Windows.Controls.Primitives. --- v2rayN/v2rayN/Views/MainWindow.xaml.cs | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index b837f65c..fdabb5f6 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -1,7 +1,9 @@ using System.ComponentModel; using System.Reactive.Disposables; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; @@ -23,6 +25,8 @@ public partial class MainWindow { InitializeComponent(); + Loaded += MainWindow_Loaded; + _config = AppHandler.Instance.Config; ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); @@ -155,6 +159,15 @@ public partial class MainWindow })); } + private void MainWindow_Loaded(object sender, RoutedEventArgs e) + { + var popupBox = themePopupBox; + + var toggleButton = FindVisualChild(popupBox, "PART_Toggle"); + + AutomationProperties.SetName(toggleButton, ServiceLib.Resx.ResUI.MoreOptions); + } + private void DelegateSnackMsg(string content) { Application.Current?.Dispatcher.Invoke((() => @@ -466,5 +479,26 @@ public partial class MainWindow } } + private T FindVisualChild(DependencyObject parent, string name) where T : DependencyObject + { + if (parent == null) + return null; + + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) + { + var child = VisualTreeHelper.GetChild(parent, i); + if (child is T childType && child is FrameworkElement element && element.Name == name) + { + return childType; + } + + var result = FindVisualChild(child, name); + if (result != null) + return result; + } + + return null; + } + #endregion UI }