终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

38 Zeilen
1.4 KiB

  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. }