1

Hi I am trying to filter a ListBox using CollectionViewSource and ICollectionView but I am not able to access them. The definetion does not have the above mention properties. Any idea why? I am developing an Windows based universal application.

My aim is to filter the list box as per the text entered in the text box.

Thank you for your help in advance

XAML

 <TextBox x:Name="txtSearch"/>
 <ListBox x:Name="lbCustomers">

XAML.cs

 public MainPage()
    {
        this.InitializeComponent();
        customerList = new List<string>();
        customerList.Add("Andrew");
        customerList.Add("bravo");
        customerList.Add("Carol");
        customerList.Add("Dela");
        customerList.Add("Eva");
        customerList.Add("family");
        customerList.Add("George");
        customerList.Add("Health");
        customerList.Add("Illa");
        customerList.Add("Jack");
        customerList.Add("Andrew");
        lbCustomers.ItemsSource = customerList;

        //llectionViewSource collectionViewSource = new CollectionViewSource();
        //ollectionViewSource.Source = customerList;
        //ollectionView collectionView = collectionViewSource.View;

        ICollectionView view = CollectionViewSource.GetDefaultView(customerList);

        view.Filter = obj =>
        {
            string item = obj as string;
            return (item.ToLower().Contains(YourFilter));
        };
    }

Metadata for CollectionViewSource

public sealed class CollectionViewSource : DependencyObject, ICollectionViewSource
{
    public CollectionViewSource();

    public static DependencyProperty IsSourceGroupedProperty { get; }
    public static DependencyProperty ItemsPathProperty { get; }
    public static DependencyProperty SourceProperty { get; }
    public static DependencyProperty ViewProperty { get; }
    public System.Boolean IsSourceGrouped { get; set; }
    public PropertyPath ItemsPath { get; set; }
    public System.Object Source { get; set; }
    public ICollectionView View { get; }
}
BRDroid
  • 3,920
  • 8
  • 65
  • 143

0 Answers0