ScrollViewer with Padding cut content and not scrollable to end
See original GitHub issueDescribe the bug
This is a bug that come from various generations of avalonia that presents a big annoyance.
When using Padding
on a ScrollViewer the content gets padded correctly, but causes a bug on scroll value that won’t show all content, this affects H and V scroll.
To Reproduce
Without padding (Work fine):
<StackPanel>
<ScrollViewer Height="200"
Background="AntiqueWhite"
VerticalAlignment="Top">
<StackPanel Spacing="5">
<NumericUpDown Value="100"/>
<NumericUpDown Value="200"/>
<NumericUpDown Value="300"/>
<NumericUpDown Value="400"/>
<NumericUpDown Value="500"/>
<NumericUpDown Value="600"/>
<NumericUpDown Value="700"/>
<NumericUpDown Value="800"/>
<NumericUpDown Value="900"/>
</StackPanel>
</ScrollViewer>
<TextBlock Text="END" Background="BlueViolet"/>
</StackPanel>
With padding=50 (Content is cut and no able to further scroll down)
<StackPanel>
<ScrollViewer Height="200"
Background="AntiqueWhite"
VerticalAlignment="Top"
Padding="50">
<StackPanel Spacing="5">
<NumericUpDown Value="100"/>
<NumericUpDown Value="200"/>
<NumericUpDown Value="300"/>
<NumericUpDown Value="400"/>
<NumericUpDown Value="500"/>
<NumericUpDown Value="600"/>
<NumericUpDown Value="700"/>
<NumericUpDown Value="800"/>
<NumericUpDown Value="900"/>
</StackPanel>
</ScrollViewer>
<TextBlock Text="END" Background="BlueViolet"/>
</StackPanel>
To solve that we must use a child content with a padding or margin and then the scroll is now correct, however that is a bit “hacky” when doing custom controls, also not expected as we would expect that padding works without produce such “bug”. It makes Padding property inside the ScrollViewer not usable at all
<StackPanel>
<ScrollViewer Height="200"
Background="AntiqueWhite"
VerticalAlignment="Top">
<StackPanel Spacing="5" Margin="50">
<NumericUpDown Value="100"/>
<NumericUpDown Value="200"/>
<NumericUpDown Value="300"/>
<NumericUpDown Value="400"/>
<NumericUpDown Value="500"/>
<NumericUpDown Value="600"/>
<NumericUpDown Value="700"/>
<NumericUpDown Value="800"/>
<NumericUpDown Value="900"/>
</StackPanel>
</ScrollViewer>
<TextBlock Text="END" Background="BlueViolet"/>
</StackPanel>
Expected behavior Padding to work and not cut content/scroll max value
Desktop (please complete the following information):
- OS: Windows 11
- Version 0.10 and 11
Additional Content
The problem looks like Padding
affect Bounds
when it should not, Margin for example do not affect Bounds, I have seen this strange behaviour on other controls like TextBox
that clips the content by using padding…
To “fix” the scroll view this hacky solution works by editing ScrollContentPresenter.cs @ 485:
var padding = Padding;
if (UseLayoutRounding)
{
var scale = LayoutHelper.GetLayoutScale(this);
padding = LayoutHelper.RoundLayoutThickness(padding, scale, scale);
}
Extent = Child!.Bounds.Size.Inflate(childMargin + padding * 2);
Still the Bounds
are incorrectly set and should be fixed to fix all controls from clip using Padding
Over the course while using Avalonia and Padding always got me problems…
Issue Analytics
- State:
- Created 2 months ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Yes, I think so. However this cannot be done in a style setter as it is “hard-coded”. We may want to swap it out into a style and disable it if the Scroller shouldn’t Autohide. I’ll try to do it, but can’t promise anything rn.
at least the scrollbar renders over the content, see: https://github.com/microsoft/microsoft-ui-xaml/issues/6703#issuecomment-1060916532
Have no idea about padding in WinUI ScrollViewer