TextBoxDialog.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using InABox.Wpf;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. namespace InABox.WPF
  5. {
  6. /// <summary>
  7. /// Interaction logic for MemoEditor.xaml
  8. /// </summary>
  9. public partial class TextBoxDialog : ThemableWindow
  10. {
  11. private readonly bool _allowblank;
  12. public TextBoxDialog(string caption, string text, bool allowblank)
  13. {
  14. _allowblank = allowblank;
  15. InitializeComponent();
  16. Title = caption;
  17. Memo.Text = text;
  18. OK.IsEnabled = _allowblank || !string.IsNullOrWhiteSpace(Memo.Text);
  19. }
  20. public string Text
  21. {
  22. get => Memo.Text;
  23. set => Memo.Text = value;
  24. }
  25. private void Memo_OnTextChanged(object sender, TextChangedEventArgs e)
  26. {
  27. OK.IsEnabled = _allowblank || !string.IsNullOrWhiteSpace(Memo.Text);
  28. }
  29. private void OK_Click(object sender, RoutedEventArgs e)
  30. {
  31. DialogResult = true;
  32. Close();
  33. }
  34. private void Cancel_Click(object sender, RoutedEventArgs e)
  35. {
  36. DialogResult = false;
  37. Close();
  38. }
  39. public static bool Execute(string caption, ref string text, bool allowblank = true)
  40. {
  41. var editor = new TextBoxDialog(caption, text, allowblank);
  42. if (editor.ShowDialog() == true)
  43. {
  44. text = editor.Memo.Text;
  45. return true;
  46. }
  47. return false;
  48. }
  49. }
  50. }