Filtering data in Silverlight

Ever want to filter data in Silverlight? here's a simple example that uses a lambda expression to search on name (case sensitive)

 

ComboBox cbx = ((ComboBox)sender);

ICollectionView dataView =
            CollectionViewSource.GetDefaultView(this.DataContext);
if (!string.IsNullOrEmpty(cbx.Text))
    dataView.Filter = f => ((Job)f).Name.Contains(cbx.Text);
else
    dataView.Filter = null;

Comments (1) -

Allan Savino
Allan Savino
1/28/2011 9:29:40 AM #

Really good stuff. Thank you for writing.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About the author

Brian Keating is a developer addicted to Microsoft Technologies.

Month List

Tag cloud

RecentComments

Comment RSS