PasswordDialog.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace InABox.Wpf.Editors
  15. {
  16. /// <summary>
  17. /// Interaction logic for PasswordDialog.xaml
  18. /// </summary>
  19. public partial class PasswordDialog : ThemableWindow
  20. {
  21. public PasswordDialog(string caption, string password = "")
  22. {
  23. InitializeComponent();
  24. Title = caption;
  25. PasswordEditor.Password = password;
  26. }
  27. public string Password
  28. {
  29. get => PasswordEditor.Password;
  30. set => PasswordEditor.Password = value;
  31. }
  32. private void OK_Click(object sender, RoutedEventArgs e)
  33. {
  34. DialogResult = true;
  35. Close();
  36. }
  37. private void Cancel_Click(object sender, RoutedEventArgs e)
  38. {
  39. DialogResult = false;
  40. Close();
  41. }
  42. public static bool Execute(string caption, ref string password)
  43. {
  44. var editor = new PasswordDialog(caption, password);
  45. if (editor.ShowDialog() == true)
  46. {
  47. password = editor.Password;
  48. return true;
  49. }
  50. return false;
  51. }
  52. }
  53. }