How to clear selection on a virtualized ListView in UWP?

Viewed 1149

I am in doubt. I have a large list container possibly thousands of items. When I virtualize (which is almost a demand for performance), I get this exception as soon as I try to update the selection:

Failed to update selection | [Exception] System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
   at System.Runtime.InteropServices.WindowsRuntime.IVector`1.RemoveAt(UInt32 index)
   at System.Runtime.InteropServices.WindowsRuntime.VectorToListAdapter.RemoveAtHelper[T](IVector`1 _this, UInt32 index)
   at System.Runtime.InteropServices.WindowsRuntime.VectorToListAdapter.RemoveAt[T](Int32 index)
   at MyApp.Views.SearchView.<>c__DisplayClass9_0.<UpdateListViewSelection>b__0()
   at MyApp.Views.SearchView.<>c__DisplayClass10_0.<<ExecuteSafely>b__0>d.MoveNext()

I tried clearing the selection in 2 ways:

A:

listView.SelectedItems.Clear();

B:

for (int i = 0; i < listView.SelectedItems.Count; i++)
{
    listView.SelectedItems.RemoveAt(i--);
}

The alternative is not to virtualize, but that's even worse... Anyone knows how to safely clear the selection on a virtualized listview in UWP?

1 Answers
Related