This commit is contained in:
ShrlAlgo
2025-07-11 09:20:23 +08:00
parent c7b104f44f
commit 4d35cadb56
840 changed files with 102347 additions and 11595 deletions

View File

@@ -0,0 +1,71 @@
using System.Windows;
using System.Windows.Controls;
namespace ShrlAlgo.Toolkit.Wpf.Attach
{
public static class PasswordBoxHelper
{
public static readonly DependencyProperty HasPasswordProperty =
DependencyProperty.RegisterAttached(
"HasPassword",
typeof(bool),
typeof(PasswordBoxHelper),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static bool GetHasPassword(DependencyObject dp)
{
return (bool)dp.GetValue(HasPasswordProperty);
}
public static void SetHasPassword(DependencyObject dp, bool value)
{
dp.SetValue(HasPasswordProperty, value);
}
public static readonly DependencyProperty MonitorPasswordProperty =
DependencyProperty.RegisterAttached(
"MonitorPassword",
typeof(bool),
typeof(PasswordBoxHelper),
new UIPropertyMetadata(false, OnMonitorPasswordChanged));
public static bool GetMonitorPassword(DependencyObject dp)
{
return (bool)dp.GetValue(MonitorPasswordProperty);
}
public static void SetMonitorPassword(DependencyObject dp, bool value)
{
dp.SetValue(MonitorPasswordProperty, value);
}
private static void OnMonitorPasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is PasswordBox passwordBox)
{
if ((bool)e.NewValue)
{
passwordBox.PasswordChanged += PasswordBox_PasswordChanged;
UpdateHasPassword(passwordBox); // Initial check
}
else
{
passwordBox.PasswordChanged -= PasswordBox_PasswordChanged;
}
}
}
private static void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (sender is PasswordBox passwordBox)
{
UpdateHasPassword(passwordBox);
}
}
private static void UpdateHasPassword(PasswordBox passwordBox)
{
SetHasPassword(passwordBox, passwordBox.Password.Length > 0);
}
}
}