mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-20 06:02:23 +00:00
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.
This commit is contained in:
parent
ea22b59287
commit
7a47a7fe0e
1 changed files with 34 additions and 0 deletions
|
@ -1,7 +1,9 @@
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Automation;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
@ -23,6 +25,8 @@ public partial class MainWindow
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
Loaded += MainWindow_Loaded;
|
||||||
|
|
||||||
_config = AppHandler.Instance.Config;
|
_config = AppHandler.Instance.Config;
|
||||||
ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false);
|
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<ToggleButton>(popupBox, "PART_Toggle");
|
||||||
|
|
||||||
|
AutomationProperties.SetName(toggleButton, ServiceLib.Resx.ResUI.MoreOptions);
|
||||||
|
}
|
||||||
|
|
||||||
private void DelegateSnackMsg(string content)
|
private void DelegateSnackMsg(string content)
|
||||||
{
|
{
|
||||||
Application.Current?.Dispatcher.Invoke((() =>
|
Application.Current?.Dispatcher.Invoke((() =>
|
||||||
|
@ -466,5 +479,26 @@ public partial class MainWindow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private T FindVisualChild<T>(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<T>(child, name);
|
||||||
|
if (result != null)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion UI
|
#endregion UI
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue