title: PowerShell XAML - Get textbox text into variable
body: <p>I am writing an application in which I need to have a dialog box for user input. The problem I am having is getting the value from a textbox into a variable after the user clicks on the button.</p>
  
  <pre><code>[xml]$XAML_ConnectDialog = @"
  &lt;Window Name="Form_ConnectDialog"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Connect" Height="176" Width="328" ResizeMode="NoResize" ShowInTaskbar="False"&gt;
      &lt;Grid&gt;
          &lt;Grid.Background&gt;
              &lt;LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0"&gt;
                  &lt;GradientStop Color="#FFB4B4B4" Offset="1"/&gt;
                  &lt;GradientStop Color="White" Offset="0.603"/&gt;
              &lt;/LinearGradientBrush&gt;
          &lt;/Grid.Background&gt;
          &lt;TextBlock TextWrapping="Wrap" Text="Enter the hostname or IP address of the remote host to connect to." Margin="10,0,10,91"/&gt;
          &lt;Label Content="Connect To:" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="76" Margin="10,47,0,0"/&gt;
          &lt;Button Name="Btn_ConnectDialog_Connect" Content="Connect" Height="20" Margin="194,88,26,20" IsDefault="True"/&gt;
          &lt;TextBox Name="Txt_ConnectDialog_Input" HorizontalAlignment="Left" Height="23" Margin="91,51,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="208"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  "@
  
  $XML_Node_Reader_ConnectDialog = (New-Object System.Xml.XmlNodeReader $XAML_ConnectDialog)
  $ConnectDialog = [Windows.Markup.XamlReader]::Load($XML_Node_Reader_ConnectDialog)
  $Btn_ConnectDialog_Connect = $ConnectDialog.FindName('Btn_ConnectDialog_Connect')
  $Txt_ConnectDialog_Input = $ConnectDialog.FindName('Txt_ConnectDialog_Input')
  
  
  $Btn_ConnectDialog_Connect.Add_Click({
      $ConnectDialog.Hide()
      $var = $Txt_ConnectDialog_Input.Text.ToString()
  
  })
  
  write-host $var
  $ConnectDialog.ShowDialog() | Out-Null
  </code></pre>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks</p>