Reputation: 99
I have a LongListSelector Element with an ItemsSource like ItemsSource="{Binding MyList}"
MyList is a ObservableCollection of MyObj. MyObj has two attributes an ID and a Name.
I'd like to filter MyList that only elements with the Name "test" will be displayed.
Can I do this in xaml code?
Thanks
Upvotes: 0
Views: 253
Reputation: 964
You can't filter your list in xaml, alter your ObservableCollection
in your code behind. In case you are using C#
this would be:
MyList = new ObservableCollection<MyObj>(allItems.Where(x => x.Name == "test"));
Upvotes: 1
Reputation: 3331
Using LINQ you can do this in code
var result = MyList.Where(w => w.Name.Equals("test"));
and to this in xaml you would need CollectionViewSource
Check these helpful links
http://www.geoffhudik.com/tech/2010/10/14/wp7-in-app-searching-filtering.html
http://code.msdn.microsoft.com/wpapps/CSWP8CollectionViewSource-41c362bf
Upvotes: 2