@@ -3,7 +3,7 @@ description: Filter the items in your collection through user input.
3
3
title : Filtering collections
4
4
label : Filtering collections
5
5
template : detail.hbs
6
- ms.date : 12/3/2019
6
+ ms.date : 3/20/2024
7
7
ms.topic : article
8
8
keywords : windows 10, uwp
9
9
pm-contact : anawish
@@ -76,14 +76,17 @@ The code below performs the filtering operation through the following steps, sho
76
76
``` csharp
77
77
using System .Linq ;
78
78
79
+ IList < Person > People ;
80
+ ObservableCollection < Person > PeopleFiltered ;
81
+
79
82
public MainPage ()
80
83
{
81
84
// Define People collection to hold all Person objects.
82
85
// Populate collection - i.e. add Person objects (not shown)
83
- IList < Person > People = new List <Person >();
86
+ People = new List <Person >();
84
87
85
88
// Create PeopleFiltered collection and copy data from original People collection
86
- ObservableCollection < Person > PeopleFiltered = new ObservableCollection <Person >(People );
89
+ PeopleFiltered = new ObservableCollection <Person >(People );
87
90
88
91
// Set the ListView's ItemsSource property to the PeopleFiltered collection
89
92
FilteredListView .ItemsSource = PeopleFiltered ;
@@ -99,7 +102,7 @@ private void FilteredLV_LNameChanged(object sender, TextChangedEventArgs e)
99
102
100
103
/* Make sure all text is case-insensitive when comparing, and make sure
101
104
the filtered items are in a List object */
102
- TempFiltered = people .Where (contact => contact .LastName .Contains (FilterByLName .Text , StringComparison .InvariantCultureIgnoreCase )).ToList ();
105
+ TempFiltered = People .Where (contact => contact .LastName .Contains (FilterByLName .Text , StringComparison .InvariantCultureIgnoreCase )).ToList ();
103
106
104
107
/* Go through TempFiltered and compare it with the current PeopleFiltered collection,
105
108
adding and subtracting items as necessary: */
0 commit comments