wp7 Collectionviewsource filtering

less than 1 minute read

Having read a recent question on the App Hub Forums I decided to update my previous post on CollectionViewSource http://babaandthepigman.wordpress.com/2011/07/03/wp7-collectionviewsource-sorting-a-listbox/ to enable filtering.

So, I added a text box to enter the filter string,

 

cvs2

 

And the following code to implement the filtering…

     private void FilterBoxTextChanged(object sender, TextChangedEventArgs e)
     {
           
Source.View.Filter = o =>
                                    
{
                                        
var item = o as Item;
                                        
if (item != null)
                                         {
                                            
return item.Text.Contains(filterBox.Text);
                                         }
                                        
return false;
                                     };
        }

and we get filtered results…

 

cvs2-2

Here’s the updated project https://skydrive.live.com/redir.aspx?cid=4f1b7368284539e5&resid=4F1B7368284539E5!436&parid=4F1B7368284539E5!123

Comments