sbaeumlisberger / VirtualizingWrapPanel

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

Load a lot of content, scroll bar drag view sluggish #38

Closed melinyi closed 2 years ago

melinyi commented 2 years ago

When loading a lot of Viewitem (images and convert), dragging the scrollbar directly can be a bit sluggish

I've set the image to Async, but it's not working very well

melinyi commented 2 years ago

I know that this may be a lot of generation and recycling caused by dragging the scrollbar. Would you consider adding timeout to handle this to determine whether the scrollbar really stops dragging

melinyi commented 2 years ago

I effectively delayed loading by doing the following

XAML: ScrollViewer.IsDeferredScrollingEnabled="True" ScrollBar.Scroll="VirtualizingItemsControl_Scroll"

C# code:

    private void VirtualizingItemsControl_Scroll(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e)
    {   
        Token = DateTime.Now.Ticks;
        SetTimeOut(Token, e.NewValue);
    }

    private long Token = 0;

    private async void SetTimeOut(long token, double newValue)
    {
         await Task.Delay(100);
        if (token != Token) return;
        ScrollViewer.ScrollToVerticalOffset(newValue);
    }