title: Why can't I select a null value in a ComboBox?
body: <p>In WPF, it seems to be impossible to select (with the mouse) a "null" value from a ComboBox. <strong>Edit</strong> To clarify, this is .NET 3.5 SP1.</p>
  
  <p>Here's some code to show what I mean. First, the C# declarations:</p>
  
  <pre><code>public class Foo
  {
      public Bar Bar { get; set; }
  }
  
  public class Bar 
  {
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>Next, my Window1 XAML:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300"&gt;
      &lt;StackPanel&gt;
          &lt;ComboBox x:Name="bars" 
                    DisplayMemberPath="Name" 
                    Height="21" 
                    SelectedItem="{Binding Bar}"
                    /&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And lastly, my Window1 class:</p>
  
  <pre><code>public partial class Window1 : Window
  {
      public Window1()
      {
          InitializeComponent();
  
          bars.ItemsSource = new ObservableCollection&lt;Bar&gt; 
          {
              null, 
              new Bar { Name = "Hello" }, 
              new Bar { Name = "World" } 
          };
          this.DataContext = new Foo();
      }
  }
  </code></pre>
  
  <p>With me? I have a ComboBox whose items are bound to a list of Bar instances, one of which is null. I have bound the window to an instance of Foo, and the ComboBox is displaying the value of its Bar property.</p>
  
  <p>When I run this app, the ComboBox starts with an empty display because Foo.Bar is null by default. That's fine. If I use the mouse to drop the ComboBox down and select the "Hello" item, that works too. But then if I try to re-select the empty item at the top of the list, the ComboBox closes and returns to its previous value of "Hello"!</p>
  
  <p>Selecting the null value with the arrow keys works as expected, and setting it programatically works too. It's only selecting with a mouse that doesn't work.</p>
  
  <p>I know an easy workaround is to have an instance of Bar that represents null and run it through an IValueConverter, but can someone explain why selecting null with the mouse doesn't work in WPF's ComboBox?</p>