PasswordDialog.xaml.cs 1.5 KB

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