Unplanned
Last Updated: 30 Jul 2018 08:13 by ADMIN
ADMIN
Martin Ivanov
Created on: 30 Jul 2018 08:12
Category: TreeView
Type: Bug Report
2
TreeView: InvalidOperationException is thrown when the ItemsSource collection is reordered at runtime and an item is selected
When you reorder the collection very fast an exception is thrown. This is reproducible when the UI virtualization is enabled with its virtualization mode set to Recycling, and an item is selected. Also, you can observe some missing items glitches instead of the exception. To reproduce this you can call the ObservableCollection's Move() method several times in a single method (see the attached project). 

In this case also a NullReferenceException is thrown sometimes instead of the InvalidOperationException.

To work this around delay the reordering calls so that the treeview has time to properly measure and arrange itself. For example:

Items.Move(10, 2);
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Items.Move(10, 2);
}), System.Windows.Threading.DispatcherPriority.Background);
0 comments