I use the standard wpf / mvvm application, where I bind combo fields to collections in the ViewModel.
I need to be able to deselect a dropdown. Meaning, users should be able to select something, and then decide that they want to cancel it (select none) for it. the problem is that there are no empty elements in my linked collection
my initial thought was to simply insert a new item into the collection, which would cause the collection to have an empty item.
this is a hack, but it affects all the code that uses this collection in the view model.
for example, if someone had to write
_myCollection.Frist(o => o.Name == "foo")
this will result in a null reference exception.
Possible workaround:
_myCollection.Where(o => o != null).First(o => o.Name == "foo");
, , - .
/ , . ( CollectionView, - )
@hbarck CompositeCollection ( )
public CompositeCollection MyObjects {
get {
var col = new CompositeCollection();
var cc1 = new CollectionContainer();
cc1.Collection = _actualCollection;
var cc2 = new CollectionContainer();
cc2.Collection = new List<MyObject>() { null };
col.Add(cc2);
col.Add(cc1);
return col;
}
}
( SelectedItem), .
, , , SelectedItem .
:
cc2.Collection = new List<MyObject>() { new MyObject() };
setter, null.. setter / reset, .