I have a CollectionViewSource for my ComboBox. Now I want to add an 'empty element' or a 'null element' to the collection. To give the use the ability deselect the current selection.
Normally, I would use a CompositeCollection for this task (like this), since I don't want to handle such things in my ViewModel or in code-behind (.xaml.cs).
Here are the related code snippets:
<UserControl.Resources>
<CollectionViewSource x:Key="FooItemsCollection" Source="{Binding FooItems}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Name" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
<ComboBox SelectedItem="{Binding SelectedFooItem, Mode=TwoWay}"
ItemsSource="{Binding Source={StaticResource FooItemsCollection}}"
IsSynchronizedWithCurrentItem="False"
DisplayMemberPath="Name" />
Is there any nice solution for this?
EDIT It is necessary, that SelectedFooItem will be set to null, when selecting this null-element.