I have a shopping list app. My Items have some properties like string Name, bool InList
. And they implement the INotifyPropertyChanged
thing. It works so far.
I get the items from a server and store them in a ObservableCollection<Item> AllItemsInDataBase
.
In the user interface I have
- A
List
with all Items (for debug purposes)
- A
List
with the items already in the shopping List
(item.InList == true
)
- A
TextBox
where users can type names and they "are offered" with items with similar name.
For the full list I simply create a ListBox
and attached the ItemsSource
to AllItemsInDataBase
it works like a charm. They appear as they load in and everything's cool
Now for the two other lists (items in the shopping list, and items matching the search word) I created a ListCollectionView, attached it to the main list and added a Filter
. Like that:
public ListCollectionView ItemsInList;
ItemsInList = CollectionViewSource.GetDefaultView(AllItemsInDataBase) as ListCollectionView;
ItemsInList.Filter = i => (i as Item).InList ;
//fill sources for ListBox in the UI
shoppingListLB.ItemsSource = ItemsInList;
allItemsLB.ItemsSource = AllItemsInDataBase;
And my problem is that BOTH list get filtered!
How do you create different simultaneous views for the same collection and display them at the same time ??
PS: Once it is working I will create another view with the Items matching the search box, so I need three concurrent filters
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…