requireAdministrator

This commit is contained in:
Orbmu2k
2026-03-23 03:51:33 +01:00
parent 4fbdb0ac7e
commit 897ac023a6
3 changed files with 1 additions and 179 deletions

View File

@@ -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<TextBox>(popupContent);
}
private static T FindVisualChild<T>(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<T>(child);
if (descendant != null)
return descendant;
}
return null;
}
}
}

View File

@@ -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);
}
}

View File

@@ -4,7 +4,7 @@
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>