Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect vertical scrollbar size in VirtualizingStackPanel #17460

Open
BobLd opened this issue Nov 9, 2024 · 0 comments · May be fixed by #17461
Open

Incorrect vertical scrollbar size in VirtualizingStackPanel #17460

BobLd opened this issue Nov 9, 2024 · 0 comments · May be fixed by #17461
Labels

Comments

@BobLd
Copy link
Contributor

BobLd commented Nov 9, 2024

Describe the bug

When using a Vertical VirtualizingStackPanel, the Vertical scroll bar size is not correct until the view is scroll down to its maximum.

Incorrect (Current)
image

Expected
image

Sorry for the bad pictures, this is part of an app I'm working on. The current hack I am using is to force a ScrollIntoView of the last item

    private void EnsureScrollBars()
    {
        int currentPage = SelectedPageIndex.HasValue ? SelectedPageIndex.Value - 1 : 0;

        try
        {
            _isSettingPageVisibility = true;

            // There's a bug in VirtualizingStackPanel. Scroll bars do not display correctly
            // This hack fixes that by scrolling into view a page that's not realised
            if (currentPage >= GetMinPageIndex() && currentPage <= GetMaxPageIndex())
            {
                // Current page is realised
                if (currentPage != 0)
                {
                    ScrollIntoView(0);
                }
                else if (currentPage != PageCount - 1)
                {
                    ScrollIntoView(PageCount - 1);
                }
            }
        }
        finally
        {
            _isSettingPageVisibility = false;

            ScrollIntoView(currentPage);
        }
    }

After investigation, it is my understanding that the problem comes from the VirtualizingStackPanel.MeasureOverride(..):

The CalculateDesiredSize(...) is called before the _lastEstimatedElementSizeU variable is set (i.e. the default value 25 is used).

I will create a PR to fix this issue

To Reproduce

See https://github.com/BobLd/Caly

I'm currently using a hack in PdfPageItemsControl (see EnsureScrollBars())

I you comment this code and open a pdf document with the app, you will see that the vertical scroll bar is not correct

Expected behavior

No response

Avalonia version

11.2.0

OS

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant