title: WPF Combobox SelectedIndex Property Binding Not working
body: <p>I am trying to bind the SelectedIndex property of combobox to my ViewModel. Here is the code.</p>
  
  <p><strong>Xaml:</strong></p>
  
  <pre><code>&lt;ComboBox x:Name="BloodGroupFilter" SelectedIndex="{Binding Path=SelectedBloodGroupIndex, Mode=TwoWay}"&gt;
      &lt;ComboBox.ItemsSource&gt;
          &lt;CompositeCollection&gt;
              &lt;ComboBoxItem Foreground="red" FontStyle="Italic"&gt;No Filter&lt;/ComboBoxItem&gt;
              &lt;CollectionContainer Collection="{Binding Source={StaticResource BloodGroupEnum}}"/&gt;
          &lt;/CompositeCollection&gt;
      &lt;/ComboBox.ItemsSource&gt;
  &lt;/ComboBox&gt;
  </code></pre>
  
  <p><strong>ViewModel</strong></p>
  
  <pre><code>private int _selectedBloodGroupIndex = 4;
  public int SelectedBloodGroupIndex {
      get { return _selectedBloodGroupIndex; }
      set { 
          _selectedBloodGroupIndex = value; 
      }
  }
  </code></pre>
  
  <p>As you can see I am trying to set the SelectedIndex of combobox to "4". This doesn't happen and SelectedIndex is set to 0. Also, when user selects a particular item of the combobox, I was expecting that the ViewModel's SelectedBloodGroupIndex property will update itself to the currently selected item of combobox, but this doesn't happen either. The ViewModel property is never invoked(both set and get). Any reasons why binding is failing for the above code.</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;ObjectDataProvider x:Key="BloodGroupEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}"&gt;
          &lt;ObjectDataProvider.MethodParameters&gt;
              &lt;x:Type TypeName="enums:BloodGroup" /&gt;
          &lt;/ObjectDataProvider.MethodParameters&gt;
      &lt;/ObjectDataProvider&gt;
  &lt;/UserControl.Resources&gt;
  </code></pre>