WPF directional navigation in ListView with data virtualisation

238 views Asked by At

I have implemented data and UI virtualisation with a ListBox in WPF according to this article. Briefly, I am binding a ListView to a collection that automatically loads data a page at a time as and when it is needed. If the ListView requests an item on a page that has not been loaded, the collection will return null, load the page asynchronously, then emit a Reset NotifyCollectionChanged event so that the ListView will pick up the actual value.

When I try to navigate through the list with the direction keys, this works fine until I hit an item that was not loaded when the ListView first received focus. At this point, the ListView itself becomes focused. If I make sure all of the data is loaded to begin with by scrolling through the list (thus forcing all items to be visualised and therefore loaded), the directional navigation works like normal.

It looks like the ListView is somehow remembering data that was originally null and refusing to move the focus to those items. What is happening here? How can I fix this?

1

There are 1 answers

0
Gordon Leigh On

Turns out focus was lost when the collection was reset. To avoid this, I raised Replace notifications instead.