123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using InABox.Wpf;
- using System.Windows;
- using System.Windows.Controls;
- namespace InABox.WPF
- {
- /// <summary>
- /// Interaction logic for MemoEditor.xaml
- /// </summary>
- public partial class TextBoxDialog : ThemableWindow
- {
- private readonly bool _allowblank;
-
- public TextBoxDialog(string caption, string text, bool allowblank)
- {
- _allowblank = allowblank;
- InitializeComponent();
- Title = caption;
- Memo.Text = text;
- OK.IsEnabled = _allowblank || !string.IsNullOrWhiteSpace(Memo.Text);
- }
- public string Text
- {
- get => Memo.Text;
- set => Memo.Text = value;
- }
-
- private void Memo_OnTextChanged(object sender, TextChangedEventArgs e)
- {
- OK.IsEnabled = _allowblank || !string.IsNullOrWhiteSpace(Memo.Text);
- }
- private void OK_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = true;
- Close();
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- Close();
- }
- public static bool Execute(string caption, ref string text, bool allowblank = true)
- {
- var editor = new TextBoxDialog(caption, text, allowblank);
- if (editor.ShowDialog() == true)
- {
- text = editor.Memo.Text;
- return true;
- }
- return false;
- }
- }
- }
|