title: ComboBox does not select proper item when bound to CompositeCollection
body: <p>I have a ComboBox bound to a collection of animals. From it I select my favourite animal. I need a static null item above the bound items. I declare it using a CompositeCollection. When the ComboBox is bound it <strong>does not select my initial favourite animal. How can I fix that?</strong> Similar problem <a href="https://stackoverflow.com/questions/10740560/combobox-losing-selectedindex">here</a> but still unresolved.</p>
  
  <p>Observations:</p>
  
  <ul>
  <li>Binding to the static item works i.e. if I don't have an initial favourite animal the static item gets selected.</li>
  <li>The problem disappears if the static item is removed. Of course this would make the CompositeCollection and this whole question obsolete.</li>
  </ul>
  
  <p>I already applied these measures:</p>
  
  <ul>
  <li>A CollectionContainer cannot bind directly to a property as outlined <a href="https://stackoverflow.com/questions/6446699/how-do-you-bind-a-collectioncontainer-to-a-collection-in-a-view-model">here</a>.</li>
  <li>The composite collection is also moved to a static resource as suggested <a href="https://stackoverflow.com/questions/12750784/how-do-i-convert-a-combobox-to-use-a-bound-compositecollection">here</a>.</li>
  </ul>
  
  <p>Complete C# code and XAML to demonstrate the problem:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Windows;
  using System.Windows.Controls;
  
  namespace WpfApplication1
  {
      public class Animal
      {
          public int Id { get; set; }
          public string Name { get; set; }
      }
  
      public class Zoo
      {
          private IEnumerable&lt;Animal&gt; _animals = new Animal[]
          {
              new Animal() { Id = 1, Name = "Tom" },
              new Animal() { Id = 2, Name = "Jerry" }
          };
  
          public Zoo(int initialId)
          {
              FavouriteId = initialId;
          }
  
          public int FavouriteId { get; set; }
          public IEnumerable&lt;Animal&gt; Animals { get { return _animals; } }
      }
  
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
  
          private void BindComboBox(object sender, RoutedEventArgs e)
          {
              // Selecting the static item by default works.
              //DataContext = new Zoo(-1);
  
              // Selecting "Jerry" by default does not work.
              DataContext = new Zoo(2);
          }
      }
  }
  </code></pre>
  
  <p>XAML</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:WpfApplication1"&gt;
  
      &lt;Window.Resources&gt;
          &lt;CollectionViewSource x:Key="AnimalsBridge" Source="{Binding Path=Animals}" /&gt;
  
          &lt;CompositeCollection x:Key="AnimalsWithNullItem"&gt;
              &lt;local:Animal Id="-1" Name="Pick someone..."/&gt;
              &lt;CollectionContainer Collection="{Binding Source={StaticResource AnimalsBridge}}" /&gt;
          &lt;/CompositeCollection&gt;
      &lt;/Window.Resources&gt;
  
      &lt;StackPanel&gt;
          &lt;Button Content="Bind" Click="BindComboBox"/&gt;
  
          &lt;ComboBox x:Name="cmbFavourite"
              SelectedValue="{Binding Path=FavouriteId}"
              SelectedValuePath="Id" DisplayMemberPath="Name"
              ItemsSource="{StaticResource AnimalsWithNullItem}"/&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>