dotnet / dotnet/wpf

ScrollViewer: add a switch to prevent content from growing outside the visible area when it does not have to

Open
#8,222 3 comments 4 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

At present, if a `ScrollViewer` has a descendent element that is also a scrollable control, said descendent will always grow to its maximum size rather than taking advantage of the fact that it is _also_ capable of scrolling. It would be nice if there was a setting on `ScrollViewer` to clamp such descendents down to the visible area when possible, only showing scrollbars when the content can shrink no further (e.g., the area is smaller than a minimum size assigned to the contents).

Example (project attached):
[testscrollviewer.zip](https://github.com/dotnet/wpf/files/12611815/testscrollviewer.zip)

How I'd like it to look:
![image](https://github.com/dotnet/wpf/assets/3289668/b9304f95-d35f-4ec5-bfe4-545b75b226b0)

How it looks:
![image](https://github.com/dotnet/wpf/assets/3289668/2ba25e05-5f15-4214-9b35-fa64d1b5fbe5)

---

I know of ways to _mostly_ accomplish this currently with hacks like binding the max height/width of `FooControl` to a parent (e.g., `ScrollContentPresenter` or `ScrollViewer` itself), but this isn't perfect, and some cases contain foot guns.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.