浏览代码

Added optional prompt to TextEdit dialog

frankvandenbos 6 月之前
父节点
当前提交
67f8809d61
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 2 1
      inabox.wpf/Editors/TextEdit.xaml
  2. 21 0
      inabox.wpf/Editors/TextEdit.xaml.cs

+ 2 - 1
inabox.wpf/Editors/TextEdit.xaml

@@ -17,10 +17,11 @@
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="Auto" />
-            <ColumnDefinition Width="Auto" />
+            <ColumnDefinition Width="*" />
         </Grid.ColumnDefinitions>
 
         <Label Grid.Row="0"
+               x:Name="Prompt"
                Grid.Column="0"
                VerticalContentAlignment="Center"
                Content="Enter Text:">

+ 21 - 0
inabox.wpf/Editors/TextEdit.xaml.cs

@@ -17,6 +17,15 @@ namespace InABox.Wpf.Editors
             TextEditor.Text = text;
         }
 
+        public TextEdit(string caption, string prompt, string text = "")
+        {
+            InitializeComponent();
+
+            Title = caption;
+            Prompt.Content = prompt;
+            TextEditor.Text = text;
+        }
+        
         public string Text
         {
             get => TextEditor.Text;
@@ -46,6 +55,18 @@ namespace InABox.Wpf.Editors
 
             return false;
         }
+        
+        public static bool Execute(string caption, string prompt, ref string text)
+        {
+            var editor = new TextEdit(caption, prompt, text);
+            if (editor.ShowDialog() == true)
+            {
+                text = editor.Text;
+                return true;
+            }
+
+            return false;
+        }
 
         private void ThemableWindow_Loaded(object sender, RoutedEventArgs e)
         {