Description
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.
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