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.
The following code works, however Visual Studio is reporting a few XAML binding failures that I don't know how to fix.
<ComboBox x:Name="NewNewComboBox"
SelectedValuePath="CompCategoryId"
DisplayMemberPath="CategoryName">
<ComboBox.Resources>
<CollectionViewSource x:Key="MyCollection" Source="{Binding Categories}"/>
</ComboBox.Resources>
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem FontStyle="Italic" FontSize="8px" Content="(clear)" />
<CollectionContainer Collection="{Binding Source={StaticResource MyCollection}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
<ComboBox.SelectedValue>
<Binding Path="CompCategoryId"/>
</ComboBox.SelectedValue>
</ComboBox>
Note: A normal ComboBox (without the (clear) item) does not show any failures.
Edit: I would like the solution to avoid code specific to the class the ComboBox uses because I want to make this ComboBox as a UserControl so it can be reused on different class (which will all have an int Id and string Name, already defined by the SelectedValuePath and DisplayMemberPath)
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)
<ComboBox x:Name="NewNewComboBox"
SelectedValuePath="CompCategoryId"
DisplayMemberPath="CategoryName"
SelectionChanged="NewNewComboBox_SelectionChanged">
<ComboBox.Resources>
<CollectionViewSource x:Key="MyCollection" Source="{Binding Categories}"/>
</ComboBox.Resources>
<ComboBox.ItemsSource>
<CompositeCollection>
<m:CompCategory CategoryName="(clear)" CompCategoryId="0"/>
<CollectionContainer Collection="{Binding Source={StaticResource MyCollection}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
<ComboBox.SelectedValue>
<Binding Path="CompCategoryId"/>
</ComboBox.SelectedValue>
</ComboBox>
private void NewNewComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (NewNewComboBox.SelectedIndex == 0) NewNewComboBox.SelectedValue = null;
}

