title: ComboBox in powershell GUI
body: <p>I have been building GUI's for a while in powershell with XAML. Everything has worked fine until I attempted to bring in ComboBox. Then powershell no longer accepts it.</p>
  
  <p>I have built the XAML in Visual Studio and it works in Design view. Every website I go to tells me this is the right XAML code. The error occurs with the code 
  <code>$reader=(New-Object System.Xml.XmlNodeReader $xaml) 
  try{$DiagForm=[Windows.Markup.XamlReader]::Load( $reader )}</code></p>
  
  <p>Here is the sample I am working with. If you take out the ComboBox segment, it works perfectly fine.</p>
  
  <pre><code>function Diag {
  [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  [xml]$XAML = @'
      &lt;Window
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Tool" Height="500" Width="300" WindowStartupLocation="CenterScreen" WindowStyle='SingleBorderWindow' ResizeMode='CanMinimize'&gt;
      &lt;Grid&gt;
          &lt;TextBox HorizontalAlignment="Center" Height="23" TextWrapping="Wrap" Text="Diagnostics" VerticalAlignment="Top" Width="300" Margin="0,-1,-0.2,0" TextAlignment="Center" Foreground="White" Background="#21C500"/&gt;
          &lt;Label Content="Report" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Margin="90,27,0,0" VerticalAlignment="Top" Width="120"/&gt;
          &lt;ComboBox HorizontalAlignment="Left" Margin="90,60,0,0" VerticalAlignment="Top" Width="120"&gt;
              &lt;ComboBoxItem MouseMove="OnHover" Name="Period1" IsSelected="True"&gt;Last 24hr&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem MouseMove="OnHover" Name="Period2" IsSelected="False"&gt;Last Week&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem MouseMove="OnHover" Name="Period3" IsSelected="False"&gt;Last Month&lt;/ComboBoxItem&gt;
          &lt;/ComboBox&gt;
          &lt;Label Content="Critical" HorizontalAlignment="Left" Margin="46,115,0,0" VerticalAlignment="Top"/&gt;
          &lt;TextBox HorizontalAlignment="Left" Height="23" Margin="124,115,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/&gt;
          &lt;Label Content="Warnings" HorizontalAlignment="Left" Margin="46,143,0,0" VerticalAlignment="Top"/&gt;
          &lt;TextBox HorizontalAlignment="Left" Height="23" Margin="124,143,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/&gt;
      &lt;/Grid&gt;
      &lt;/Window&gt;
  '@
      #Read XAML
      $reader=(New-Object System.Xml.XmlNodeReader $xaml) 
      try{$DiagForm=[Windows.Markup.XamlReader]::Load( $reader )}
      catch{Write-Host "Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit}
  
      $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $DiagForm.FindName($_.Name)}
  
  $DiagForm.ShowDialog() | out-null
  }
  Diag
  </code></pre>