Skip to content

Handle Padding correctly in ScrollContentPresenter - #21872

Merged
MrJul merged 2 commits into
AvaloniaUI:mainfrom
MrJul:fix/scrollviewer-padding
Jul 28, 2026
Merged

Handle Padding correctly in ScrollContentPresenter#21872
MrJul merged 2 commits into
AvaloniaUI:mainfrom
MrJul:fix/scrollviewer-padding

Conversation

@MrJul

@MrJul MrJul commented Jul 28, 2026

Copy link
Copy Markdown
Member

What does the pull request do?

This PR ensures that the Padding (and the BorderThickness) of a ScrollContentPresenter is correctly taken into account when measuring or arranging its content.

What is the current behavior?

The padding in a direction that contains a scrollbar is ignored, and the content can't scroll to its end.

What is the updated/expected behavior with this PR?

The padding is correctly taken into account and is visible. The content is scrolled correctly.

Notes

Note that contrary to WPF, the padding is inside the scrolling area (matching WinUI). It was already the case before this PR, and changing that would be a behavioral breaking change. Users wanting the WPF behavior can simply set a Margin on the ScrollContentPresenter instead.

Fixed issues

@MrJul MrJul added bug backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 28, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067837-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul
MrJul added this pull request to the merge queue Jul 28, 2026
Merged via the queue into AvaloniaUI:main with commit 06cf8ef Jul 28, 2026
11 checks passed
@MrJul
MrJul deleted the fix/scrollviewer-padding branch July 28, 2026 14:20
MrJul added a commit that referenced this pull request Jul 29, 2026
* Add failing ScrollViewer tests

* Handle Padding correctly in ScrollContentPresenter
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 29, 2026
@zrt2399

zrt2399 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Hi @MrJul, thank you for the fix. Unlike WPF, where ScrollViewer.Padding is taken into account during scrolling, support for equivalent behavior is not included in this PR. Is this behavior expected?

 <Border Height="400"
         BorderBrush="Gray"
         BorderThickness="1">
     <ScrollViewer Padding="20" VerticalScrollBarVisibility="Auto">
         <Button Height="600">Button</Button>
     </ScrollViewer>
 </Border>
bugdemo bugdemo1

@MrJul

MrJul commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

Yes, as mentioned in the PR:

Note that contrary to WPF, the padding is inside the scrolling area (matching WinUI). It was already the case before this PR, and changing that would be a behavioral breaking change. Users wanting the WPF behavior can be simply set a Margin on the ScrollContentPresenter instead.

WPF behavior:

<Border Height="400"
        BorderBrush="Gray"
        BorderThickness="1">
  <ScrollViewer VerticalScrollBarVisibility="Auto">
    <ScrollViewer.Styles>
      <Style Selector="ScrollContentPresenter">
        <Setter Property="Margin" Value="20" />
      </Style>
    </ScrollViewer.Styles>
    <Button Height="600">Button</Button>
  </ScrollViewer>
</Border>

@zrt2399

zrt2399 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Yes, as mentioned in the PR:

Note that contrary to WPF, the padding is inside the scrolling area (matching WinUI). It was already the case before this PR, and changing that would be a behavioral breaking change. Users wanting the WPF behavior can be simply set a Margin on the ScrollContentPresenter instead.

WPF behavior:

<Border Height="400"
        BorderBrush="Gray"
        BorderThickness="1">
  <ScrollViewer VerticalScrollBarVisibility="Auto">
    <ScrollViewer.Styles>
      <Style Selector="ScrollContentPresenter">
        <Setter Property="Margin" Value="20" />
      </Style>
    </ScrollViewer.Styles>
    <Button Height="600">Button</Button>
  </ScrollViewer>
</Border>

Thanks for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScrollViewer not scrolling to end with bottom padding...

4 participants