question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ScrollViewer with Padding cut content and not scrollable to end

See original GitHub issue

Describe 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>

image


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>

image


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>

image

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…

image

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:open
  • Created 2 months ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
timuniecommented, Jul 24, 2023

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.

0reactions
timuniecommented, Jul 26, 2023

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

ScrollViewer not scrolling in WPF
Try a grid around your ScrollViwer instead of the StackPanel . I think StackPanel will provide as much height as the internal content...
Read more >
Bottom of scrollbar is cut off in browser
I trying to use a rad splitter within a fixed header. There is a left pane for navigation and notification and a main...
Read more >
ScrollViewer Class (Windows.UI.Xaml.Controls)
Represents a scrollable area that can contain other visible elements. ... When the content of the ScrollViewer is not entirely visible, the ScrollViewer...
Read more >
How to Hide the Scrollbar in CSS
Learn how to hide the scrollbar in CSS, plus how to disable scrolling or keep scrolling enabled on your website.
Read more >
scrollbar-gutter - CSS: Cascading Style Sheets - MDN Web Docs
An element's scrollbar gutter is the space between the inner border edge and the outer padding edge, where the browser may display a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found