Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just add a static method to call it like a MessageBox:</p> <pre><code>&lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x:Class="utils.PromptDialog" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowStartupLocation="CenterScreen" SizeToContent="WidthAndHeight" MinWidth="300" MinHeight="100" WindowStyle="SingleBorderWindow" ResizeMode="CanMinimize"&gt; &lt;StackPanel Margin="5"&gt; &lt;TextBlock Name="txtQuestion" Margin="5"/&gt; &lt;TextBox Name="txtResponse" Margin="5"/&gt; &lt;PasswordBox Name="txtPasswordResponse" /&gt; &lt;StackPanel Orientation="Horizontal" Margin="5" HorizontalAlignment="Right"&gt; &lt;Button Content="_Ok" IsDefault="True" Margin="5" Name="btnOk" Click="btnOk_Click" /&gt; &lt;Button Content="_Cancel" IsCancel="True" Margin="5" Name="btnCancel" Click="btnCancel_Click" /&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>And the code behind:</p> <pre><code>public partial class PromptDialog : Window { public enum InputType { Text, Password } private InputType _inputType = InputType.Text; public PromptDialog(string question, string title, string defaultValue = "", InputType inputType = InputType.Text) { InitializeComponent(); this.Loaded += new RoutedEventHandler(PromptDialog_Loaded); txtQuestion.Text = question; Title = title; txtResponse.Text = defaultValue; _inputType = inputType; if (_inputType == InputType.Password) txtResponse.Visibility = Visibility.Collapsed; else txtPasswordResponse.Visibility = Visibility.Collapsed; } void PromptDialog_Loaded(object sender, RoutedEventArgs e) { if (_inputType == InputType.Password) txtPasswordResponse.Focus(); else txtResponse.Focus(); } public static string Prompt(string question, string title, string defaultValue = "", InputType inputType = InputType.Text) { PromptDialog inst = new PromptDialog(question, title, defaultValue, inputType); inst.ShowDialog(); if (inst.DialogResult == true) return inst.ResponseText; return null; } public string ResponseText { get { if (_inputType == InputType.Password) return txtPasswordResponse.Password; else return txtResponse.Text; } } private void btnOk_Click(object sender, RoutedEventArgs e) { DialogResult = true; Close(); } private void btnCancel_Click(object sender, RoutedEventArgs e) { Close(); } } </code></pre> <p>So you can call it like:</p> <pre><code>string repeatPassword = PromptDialog.Prompt("Repeat password", "Password confirm", inputType: PromptDialog.InputType.Password); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload