title: XAML Binding Failures on ComboBox
body: <p>I have created a ComboBox that adds an item inside XAML, this is so I can have an uneditable ComboBox with an option that will set the binded item null.</p>
  <p><a href="https://i.stack.imgur.com/9w9ns.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9w9ns.png" alt="ComboBox Clear Screenshot" /></a></p>
  <p>The following code works, however Visual Studio is reporting a few XAML binding failures that I don't know how to fix.</p>
  <pre><code>&lt;ComboBox x:Name=&quot;NewNewComboBox&quot;
            SelectedValuePath=&quot;CompCategoryId&quot;
            DisplayMemberPath=&quot;CategoryName&quot;&gt;
      &lt;ComboBox.Resources&gt;
          &lt;CollectionViewSource x:Key=&quot;MyCollection&quot; Source=&quot;{Binding Categories}&quot;/&gt;
      &lt;/ComboBox.Resources&gt;
      &lt;ComboBox.ItemsSource&gt;
          &lt;CompositeCollection&gt;
              &lt;ComboBoxItem FontStyle=&quot;Italic&quot; FontSize=&quot;8px&quot; Content=&quot;(clear)&quot; /&gt;
              &lt;CollectionContainer Collection=&quot;{Binding Source={StaticResource MyCollection}}&quot;  /&gt;
          &lt;/CompositeCollection&gt;
      &lt;/ComboBox.ItemsSource&gt;
      &lt;ComboBox.SelectedValue&gt;
          &lt;Binding Path=&quot;CompCategoryId&quot;/&gt;
      &lt;/ComboBox.SelectedValue&gt;
  &lt;/ComboBox&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/VTzzY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VTzzY.png" alt="XAML Binding Failures Screenshot" /></a></p>
  <p>Note: A normal ComboBox (without the <em>(clear)</em> item) does not show any failures.</p>
  <p><strong>Edit:</strong> I would like the solution to avoid code specific to the class the ComboBox uses because I want to make this ComboBox as a <strong>UserControl</strong> so it can be reused on different class (which will all have an int <em>Id</em> and string <em>Name</em>, already defined by the SelectedValuePath and DisplayMemberPath)</p>
  <p>I have amended the ComboBoxItem and no longer receive XAML Binding Failures.  But I cannot edit the FontStyle of it (and I have no clue how to implement this as a re-usable UserControl)</p>
  <pre><code>&lt;ComboBox x:Name=&quot;NewNewComboBox&quot;
            SelectedValuePath=&quot;CompCategoryId&quot;
            DisplayMemberPath=&quot;CategoryName&quot;
            SelectionChanged=&quot;NewNewComboBox_SelectionChanged&quot;&gt;
      &lt;ComboBox.Resources&gt;
          &lt;CollectionViewSource x:Key=&quot;MyCollection&quot; Source=&quot;{Binding Categories}&quot;/&gt;
      &lt;/ComboBox.Resources&gt;
      &lt;ComboBox.ItemsSource&gt;
          &lt;CompositeCollection&gt;
              &lt;m:CompCategory CategoryName=&quot;(clear)&quot; CompCategoryId=&quot;0&quot;/&gt;
              &lt;CollectionContainer Collection=&quot;{Binding Source={StaticResource MyCollection}}&quot;  /&gt;
          &lt;/CompositeCollection&gt;
      &lt;/ComboBox.ItemsSource&gt;
      &lt;ComboBox.SelectedValue&gt;
          &lt;Binding Path=&quot;CompCategoryId&quot;/&gt;
      &lt;/ComboBox.SelectedValue&gt;
  &lt;/ComboBox&gt;
  
  private void NewNewComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
      if (NewNewComboBox.SelectedIndex == 0) NewNewComboBox.SelectedValue = null;
  }
  </code></pre>