终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

PasswordBoxHelper.cs 1.4 KiB

hace 2 años
12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. namespace FryPot_DosingSystem.Helper
  9. {
  10. public class PasswordBoxHelper
  11. {
  12. public static string GetPasswordContent(DependencyObject obj) => (string)obj.GetValue(PasswordContentProperty);
  13. public static void SetPasswordContent(DependencyObject obj, string value) => obj.SetValue(PasswordContentProperty, value);
  14. public static readonly DependencyProperty PasswordContentProperty =
  15. DependencyProperty.RegisterAttached("PasswordContent", typeof(string), typeof(PasswordBoxHelper),
  16. new PropertyMetadata(string.Empty, OnPasswordContentPropertyChanged));
  17. private static void OnPasswordContentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  18. {
  19. var box = d as PasswordBox;
  20. box.PasswordChanged -= OnPasswordChanged;
  21. var password = (string)e.NewValue;
  22. if (box != null && box.Password != password)
  23. box.Password = password;
  24. box.PasswordChanged += OnPasswordChanged;
  25. }
  26. private static void OnPasswordChanged(object sender, RoutedEventArgs e)
  27. {
  28. var box = sender as PasswordBox;
  29. SetPasswordContent(box, box.Password);
  30. }
  31. }
  32. }