PassWordView.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. namespace MECF.Framework.RT.Core.Backend
  16. {
  17. /// <summary>
  18. /// PassWord.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class PassWordView : Window
  21. {
  22. public bool VerificationResult { get; set; }
  23. public string Password { get; set; }
  24. public PassWordView(string password = "")
  25. {
  26. InitializeComponent();
  27. this.Closing += PassWordView_Closing;
  28. this.Loaded += PassWordView_Loaded;
  29. this.IsVisibleChanged += PassWordView_IsVisibleChanged;
  30. Password = password;
  31. }
  32. private void PassWordView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  33. {
  34. if (IsVisible)
  35. PasswordBox.Focus();
  36. }
  37. private void PassWordView_Loaded(object sender, RoutedEventArgs e)
  38. {
  39. PasswordBox.Focus();
  40. }
  41. private void PassWordView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  42. {
  43. e.Cancel = true;
  44. Hide();
  45. }
  46. private void EnsureButton_Click(object sender, RoutedEventArgs e)
  47. {
  48. if (!string.IsNullOrEmpty(Password)?
  49. PasswordBox.Password == Password:
  50. (PasswordBox.Password == "123456" || PasswordBox.Password == "admin"))
  51. {
  52. VerificationResult = true;
  53. Hide();
  54. }
  55. else
  56. {
  57. PasswordBox.Foreground = new SolidColorBrush(Colors.Red);
  58. VerificationResult = false;
  59. }
  60. }
  61. public void Reset()
  62. {
  63. PasswordBox.Password = "";
  64. VerificationResult = false;
  65. }
  66. private void CancelButton_Click(object sender, RoutedEventArgs e)
  67. {
  68. this.Hide();
  69. }
  70. private void PasswordBox_OnPasswordChanged(object sender, RoutedEventArgs e)
  71. {
  72. PasswordBox.Foreground = new SolidColorBrush(Colors.Black);
  73. }
  74. private void PasswordBox_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  75. {
  76. }
  77. private void PasswordBox_OnTextInput(object sender, TextCompositionEventArgs e)
  78. {
  79. }
  80. }
  81. }