WPF Filter a ListBox

后端 未结 3 1031
耶瑟儿~
耶瑟儿~ 2020-12-02 00:01

I have a ListBox with binding to a list of strings. I want to filter the list when I enter text in a TextBox. How can I do it?

publ         


        
3条回答
  •  不思量自难忘°
    2020-12-02 00:24

    CollectionViewSource class can help here. As far as I can tell it has many capabilities to filter, sort and group collections.

    ICollectionView view = CollectionViewSource.GetDefaultView(ElementList);
    view.Filter = (o) => {return o;}//here is the lambda with your conditions to filter
    

    When you don't need any filter just set view.Filter to null. Also check out this article on filtering

提交回复
热议问题