From 897ac023a625f162553a5eded4e8893672539c54 Mon Sep 17 00:00:00 2001 From: Orbmu2k Date: Mon, 23 Mar 2026 03:51:33 +0100 Subject: [PATCH] requireAdministrator --- .../Common/Helper/ComboBoxHelper.cs | 140 ------------------ .../Common/Helper/TextBoxHelper.cs | 38 ----- nvidiaProfileInspector/app.manifest | 2 +- 3 files changed, 1 insertion(+), 179 deletions(-) delete mode 100644 nvidiaProfileInspector/Common/Helper/ComboBoxHelper.cs delete mode 100644 nvidiaProfileInspector/Common/Helper/TextBoxHelper.cs diff --git a/nvidiaProfileInspector/Common/Helper/ComboBoxHelper.cs b/nvidiaProfileInspector/Common/Helper/ComboBoxHelper.cs deleted file mode 100644 index 608fd9f..0000000 --- a/nvidiaProfileInspector/Common/Helper/ComboBoxHelper.cs +++ /dev/null @@ -1,140 +0,0 @@ -using System.Windows; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using System.Windows.Input; -using System.Windows.Media; - -namespace nvidiaProfileInspector.Common.Helper -{ - public class ComboBoxHelper - { - private ComboBoxHelper() { } - - public static readonly DependencyProperty FilterTextProperty = - DependencyProperty.RegisterAttached( - "FilterText", - typeof(string), - typeof(ComboBoxHelper), - new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); - - public static string GetFilterText(DependencyObject obj) - { - return (string)obj.GetValue(FilterTextProperty); - } - - public static void SetFilterText(DependencyObject obj, string value) - { - obj.SetValue(FilterTextProperty, value); - } - - private static ICommand _clearCommand; - public static ICommand ClearCommand => _clearCommand ?? (_clearCommand = new ClearCommandImpl()); - - private class ClearCommandImpl : ICommand - { - public bool CanExecute(object parameter) => true; - - public void Execute(object parameter) - { - if (parameter is DependencyObject obj) - SetFilterText(obj, string.Empty); - } - - public event System.EventHandler CanExecuteChanged - { - add { CommandManager.RequerySuggested += value; } - remove { CommandManager.RequerySuggested -= value; } - } - } - - public static readonly DependencyProperty AutoFocusSearchProperty = - DependencyProperty.RegisterAttached( - "AutoFocusSearch", - typeof(bool), - typeof(ComboBoxHelper), - new PropertyMetadata(false, OnAutoFocusSearchChanged)); - - public static bool GetAutoFocusSearch(DependencyObject obj) - { - return (bool)obj.GetValue(AutoFocusSearchProperty); - } - - public static void SetAutoFocusSearch(DependencyObject obj, bool value) - { - obj.SetValue(AutoFocusSearchProperty, value); - } - - private static void OnAutoFocusSearchChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is ComboBox comboBox && (bool)e.NewValue) - { - comboBox.DropDownOpened += ComboBox_DropDownOpened; - comboBox.DropDownClosed += ComboBox_DropDownClosed; - } - } - - private static void ComboBox_DropDownOpened(object sender, System.EventArgs e) - { - var comboBox = sender as ComboBox; - if (comboBox == null) - return; - - comboBox.Dispatcher.BeginInvoke(new System.Action(() => - { - var searchBox = FindSearchBox(comboBox); - if (searchBox != null) - { - searchBox.Text = string.Empty; - searchBox.Focus(); - } - }), System.Windows.Threading.DispatcherPriority.Background); - } - - private static void ComboBox_DropDownClosed(object sender, System.EventArgs e) - { - var comboBox = sender as ComboBox; - if (comboBox == null) - return; - - var searchBox = FindSearchBox(comboBox); - if (searchBox != null) - { - searchBox.Text = string.Empty; - } - } - - private static TextBox FindSearchBox(ComboBox comboBox) - { - if (comboBox.Template == null) - return null; - - var popup = comboBox.Template.FindName("Popup", comboBox) as Popup; - if (popup == null) - return null; - - var popupContent = popup.Child; - if (popupContent == null) - return null; - - return FindVisualChild(popupContent); - } - - private static T FindVisualChild(DependencyObject parent) 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 result) - return result; - - var descendant = FindVisualChild(child); - if (descendant != null) - return descendant; - } - - return null; - } - } -} diff --git a/nvidiaProfileInspector/Common/Helper/TextBoxHelper.cs b/nvidiaProfileInspector/Common/Helper/TextBoxHelper.cs deleted file mode 100644 index 2690997..0000000 --- a/nvidiaProfileInspector/Common/Helper/TextBoxHelper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Windows; -using System.Windows.Input; - -namespace nvidiaProfileInspector.Common.Helper -{ - public class TextBoxHelper - { - public static readonly DependencyProperty ClearCommandProperty = - DependencyProperty.RegisterAttached( - "ClearCommand", - typeof(ICommand), - typeof(TextBoxHelper), - new PropertyMetadata(null)); - - public static ICommand GetClearCommand(DependencyObject obj) => (ICommand)obj.GetValue(ClearCommandProperty); - public static void SetClearCommand(DependencyObject obj, ICommand value) => obj.SetValue(ClearCommandProperty, value); - - public static readonly DependencyProperty ClearCommandParameterProperty = - DependencyProperty.RegisterAttached( - "ClearCommandParameter", - typeof(object), - typeof(TextBoxHelper), - new PropertyMetadata(null)); - - public static object GetClearCommandParameter(DependencyObject obj) => obj.GetValue(ClearCommandParameterProperty); - public static void SetClearCommandParameter(DependencyObject obj, object value) => obj.SetValue(ClearCommandParameterProperty, value); - - public static readonly DependencyProperty PlaceholderProperty = - DependencyProperty.RegisterAttached( - "Placeholder", - typeof(string), - typeof(TextBoxHelper), - new PropertyMetadata(string.Empty)); - - public static string GetPlaceholder(DependencyObject obj) => (string)obj.GetValue(PlaceholderProperty); - public static void SetPlaceholder(DependencyObject obj, string value) => obj.SetValue(PlaceholderProperty, value); - } -} diff --git a/nvidiaProfileInspector/app.manifest b/nvidiaProfileInspector/app.manifest index 0addf2a..8a6b973 100644 --- a/nvidiaProfileInspector/app.manifest +++ b/nvidiaProfileInspector/app.manifest @@ -4,7 +4,7 @@ - +