简体   繁体   中英

Stop collection view filtering

I have two List boxes ,both has item source set as MyList.In listbox1 I want to filter the entries based on some predicate.I achieve that by following code

ICollectionView listview= CollectionViewSource.GetDefaultView(MyList);

listview.filter(predicate)

My problem is I dont want this filtering to be applied to listbox2 but it is important for me to keep one itemsource.How can I achieve this.

  <ListBox Name="listbox1" ItemsSource="{Binding MyList}"/>
    <ListBox Name="listbox2" ItemsSource="{Binding MyList}"/>

I tried setting VirtualizingStackpanel.IsVirtualizing to false ,but it doesnt work.

Instead of binding the source collection to the list boxes, you can create a collection view source where you need filtering and bind its view to the list box.

public CollectionViewSource ViewSource1 { get; set; }


ViewSource1 = new CollectionViewSource { Source = MyList};
ViewSource1.View.Filter(predicate1)

Then bind the View of the view source to the first list box. You can bind the source collection to the second list box.

 <ListBox Name="listbox1" ItemsSource="{Binding ViewSource1.View}"/>
 <ListBox Name="listbox2" ItemsSource="{Binding MyList}"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM