PasswordBoxControl.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace ComPDFKit.Controls.Common
  18. {
  19. /// <summary>
  20. /// Interaction logic for PasswordControl.xaml
  21. /// </summary>
  22. public partial class PasswordBoxControl : UserControl, INotifyPropertyChanged
  23. {
  24. public static readonly DependencyProperty WatermarkProperty =
  25. DependencyProperty.Register("Watermark", typeof(string), typeof(PasswordBoxControl), new PropertyMetadata(null));
  26. public string Watermark
  27. {
  28. get { return (string)GetValue(WatermarkProperty); }
  29. set { SetValue(WatermarkProperty, value); }
  30. }
  31. public static readonly DependencyProperty PasswordProperty =
  32. DependencyProperty.Register("Password", typeof(string), typeof(PasswordBoxControl), new PropertyMetadata(string.Empty));
  33. public string Password
  34. {
  35. get { return (string)GetValue(PasswordProperty); }
  36. set { SetValue(PasswordProperty, value); }
  37. }
  38. #region - Used to bind ViewModel part. -
  39. public ICommand Command
  40. {
  41. get { return (ICommand)GetValue(CommandProperty); }
  42. set { SetValue(CommandProperty, value); }
  43. }
  44. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  45. public static readonly DependencyProperty CommandProperty =
  46. DependencyProperty.Register("Command", typeof(ICommand), typeof(PasswordBoxControl), new PropertyMetadata(default(ICommand)));
  47. public object CommandParameter
  48. {
  49. get { return (object)GetValue(CommandParameterProperty); }
  50. set { SetValue(CommandParameterProperty, value); }
  51. }
  52. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  53. public static readonly DependencyProperty CommandParameterProperty =
  54. DependencyProperty.Register("CommandParameter", typeof(object), typeof(PasswordBoxControl), new PropertyMetadata(default(object)));
  55. public IInputElement CommandTarget { get; set; }
  56. #endregion
  57. public static readonly RoutedEvent PasswordChangedEvent =
  58. EventManager.RegisterRoutedEvent("PasswordChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(PasswordBoxControl));
  59. public event RoutedEventHandler PasswordChanged
  60. {
  61. add => AddHandler(PasswordChangedEvent, value);
  62. remove => RemoveHandler(PasswordChangedEvent, value);
  63. }
  64. public PasswordBoxControl()
  65. {
  66. InitializeComponent();
  67. Grid.DataContext = this;
  68. }
  69. public event PropertyChangedEventHandler PropertyChanged;
  70. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  71. {
  72. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  73. }
  74. private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  75. {
  76. if (Password == string.Empty)
  77. {
  78. DisplayPasswordChk.IsChecked = false;
  79. }
  80. }
  81. }
  82. }