Shared Size
Columns in separate grids agreeing on one width, so a list of rows lines up.
Overview
A key column beside a description column is one of the most common shapes in a terminal UI,
and the obvious way to build it — one Grid per row — does not line
up, because each grid sizes its Auto column to its own content alone. The usual
workaround is to pad the text to a guessed width in code, which then has to be re-guessed
every time the longest entry changes.
SharedSizeGroup names a row or column definition; every definition sharing that
name takes the width of the widest of them. Grid.IsSharedSizeScope on an
ancestor is what bounds the name, so two screens can both call a group
"keys" without one setting the other's width.
A definition in a group is sized from its content whatever its Width says.
Sharing a proportional width between grids means nothing, so a * in a group
behaves like Auto and is left out of the star distribution.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| ColumnDefinition.SharedSizeGroup | string? | null | Name of the group this column belongs to. |
| RowDefinition.SharedSizeGroup | string? | null | Name of the group this row belongs to. |
| Grid.IsSharedSizeScope | bool (attached) | false | Marks an element as the boundary within which group names are matched. Set it on any ancestor. |
A group with no scope above it falls back to sizing on its own content, which is what
Auto would have done — rather than silently doing nothing at all.
Auto sizing
Shared sizing is built on Auto, which measures the largest preferred size among
the children in that row or column, floored by MinWidth/MinHeight.
Only children spanning a single row or column contribute: a spanned child cannot be
attributed to one definition without deciding how to split it. Children with
Visibility="Collapsed" contribute nothing.
Key Concepts
SharedSizeGroupgoes on the row or column definition;Grid.IsSharedSizeScopegoes on an ancestor- The nearest scope wins, so the same group name in two scopes stays independent
- A grouped definition is content-sized whatever its
Width/Heightsays, and takes no part in star distribution - The group follows its content down as well as up — it does not stick at a high-water mark
- Definitions are declared in
<Grid.ColumnDefinitions>; theColumns="auto *"shorthand cannot name a group - Resolved within a single frame, so a headless capture shows the settled layout