This hapens because in WPF all Collections contain a default ICollectionView. This view can be retrieved with:
var view = CollectionViewSource.GetDefaultView(collection);
This can easily be handled if each ComboBox binds to a unique ICollectionView. It doesn't matter if the underlying Collection is the same as long as the ICollectionViews differ.
IList<ComboBoxExtDataObject> _dataObjects; public IList<ComboBoxExtDataObject> DataObjects { get { if (_dataObjects == null) { _dataObjects = new ObservableCollection<ComboBoxExtDataObject>(); for (int i = 1; i <= 50; i++) _dataObjects.Add(new ComboBoxExtDataObject { Id = i, Name = "Name" + i }); } return _dataObjects; } } ICollectionView _sources1; public ICollectionView Sources1 { get { if (_sources1 == null) { var lst = new CollectionViewSource(); lst.Source = _dataObjects; _sources1 = lst.View; } return _sources1; } } ICollectionView _sources2; public ICollectionView Sources2 { get { if (_sources2 == null) { var lst = new CollectionViewSource(); lst.Source = _dataObjects; _sources2 = lst.View; } return _sources2; } }
In this case I bind the ComboBox1 to Sources1 and the ComboBox2 to Sources2. Now I can easily use the Filtering that I added to my ComboBox without changing the CollectionView of the other ComboBox.
Keine Kommentare:
Kommentar veröffentlichen