1
Vote

ScrollInfo not reset when Items changed

description

I'm using the Virtualizing WrapPanel in a ListBox. When the source collection of the ListBox changes, the ScrollInfo of the WrapPanel doesn't get reset. This is noticable when you fill the ListBox with too many items to display on screen, so a scrollbar is visible, then scroll down a bit, then try to load only 1 item in the ListBox, which causes that item not to be displayed, because the WrapPanel is still scrollled to a position in which the top items are not visible.

To reproduce:
  • Fill the ListBox with a lot of items
  • Scroll down
  • Fill the ListBox with 1 item
    => item is invisible and scrollbar is not displayed.
I fixed this by changing your OnItemsChanged function to this:
protected override void OnItemsChanged(object sender, ItemsChangedEventArgs args)
        {
            switch (args.Action)
            {
                case NotifyCollectionChangedAction.Remove:
                case NotifyCollectionChangedAction.Replace:
                case NotifyCollectionChangedAction.Move:
                    RemoveInternalChildRange(args.Position.Index, args.ItemUICount);
                    break;
            }

            this.offset.X = 0;
            this.offset.Y = 0;
        }

comments