sbaeumlisberger / VirtualizingWrapPanel

Implementation of a comprehensive VirtualisingWrapPanel for WPF
MIT License
254 stars 35 forks source link

NullReferenceException when Grouping items and VirtualizationMode="Recycling" #24

Closed egorozh closed 3 years ago

egorozh commented 3 years ago

When scrolling down the list with grouping and VirtualizationMode="Recycling", an internal error is thrown in the method (VirtualizingPanelBase):


        /// <summary>
        /// Virtualizes (cleanups) no longer visible or cached items.
        /// </summary>
        protected virtual void VirtualizeItems()
        {
            for (int childIndex = InternalChildren.Count - 1; childIndex >= 0; childIndex--)
            {
                var generatorPosition = GetGeneratorPositionFromChildIndex(childIndex);

                int itemIndex = ItemContainerGenerator.IndexFromGeneratorPosition(generatorPosition);

                if (!ItemRange.Contains(itemIndex))
                {
                    if (VirtualizationMode == VirtualizationMode.Recycling)
                    {
                        ItemContainerGenerator.Recycle(generatorPosition, 1); // throw NullReferenceException 
                    }
                    else
                    {
                        ItemContainerGenerator.Remove(generatorPosition, 1);
                    }
                    RemoveInternalChildRange(childIndex, 1);
                }
            }
        }

.NET Version: netcore3.1, net5, net6 OS Version: Windows 10

sbaeumlisberger commented 3 years ago

Thanks for reporting this issue. I could reproduce the problem with the sample application. Unfortunately the error occurs inside the WPF framework code so I need to investigate further.

sbaeumlisberger commented 3 years ago

I have published a new nuget package fixing this issue: https://www.nuget.org/packages/VirtualizingWrapPanel/1.5.5

egorozh commented 3 years ago

Thanks)