Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Great answer of Josh, all credit to him, I slightly modified it to this however:</p> <p>MyDialog Xaml</p> <pre><code> &lt;StackPanel Margin="5,5,5,5"&gt; &lt;TextBlock Name="TitleTextBox" Margin="0,0,0,10" /&gt; &lt;TextBox Name="InputTextBox" Padding="3,3,3,3" /&gt; &lt;Grid Margin="0,10,0,0"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Button Name="BtnOk" Content="OK" Grid.Column="0" Margin="0,0,5,0" Padding="8" Click="BtnOk_Click" /&gt; &lt;Button Name="BtnCancel" Content="Cancel" Grid.Column="1" Margin="5,0,0,0" Padding="8" Click="BtnCancel_Click" /&gt; &lt;/Grid&gt; &lt;/StackPanel&gt; </code></pre> <p>MyDialog Code Behind</p> <pre><code> public MyDialog() { InitializeComponent(); } public MyDialog(string title,string input) { InitializeComponent(); TitleText = title; InputText = input; } public string TitleText { get { return TitleTextBox.Text; } set { TitleTextBox.Text = value; } } public string InputText { get { return InputTextBox.Text; } set { InputTextBox.Text = value; } } public bool Canceled { get; set; } private void BtnCancel_Click(object sender, System.Windows.RoutedEventArgs e) { Canceled = true; Close(); } private void BtnOk_Click(object sender, System.Windows.RoutedEventArgs e) { Canceled = false; Close(); } </code></pre> <p>And call it somewhere else</p> <pre><code>var dialog = new MyDialog("test", "hello"); dialog.Show(); dialog.Closing += (sender,e) =&gt; { var d = sender as MyDialog; if(!d.Canceled) MessageBox.Show(d.InputText); } </code></pre>
 

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