Filtering ObservableCollection clears selection RRS feed

  • Question

  • I wish to be able to have a GridView which displays a list of People. This is bound to my ViewModel and I want to be able to add to the GridView. I have add a popup UserControl that displays a ListView which is multiselect, when an item is selected it is added to my collection, I am using WinRT Xaml Toolkit BindableSelection for doing this.

    This works fine and adds and removes People as expected from the GridView. However I also want to be able to search/filter the list by name. When a search is done the underlying collection on the ListView is reset and therefore my selection is reset causing the main GridView to lose all it's items.

    I feel there is an issue with the way I have the bindings etc setup and perhaps I'm missing a middle step but cannot figure out what.

    I have already asked a question on Stackoverflow about this:


    Thursday, October 10, 2013 9:01 AM


  • If you are modifying the ObservableCollection in a way which removes the current selection (likely if you delete and recreate it) then the selection will be lost. To maintain it you can remember the selection before clearing the collection and then reset it afterwards.
    • Marked as answer by Anne Jing Friday, October 18, 2013 2:24 AM
    Friday, October 11, 2013 6:10 AM