fix(grid): allow shared size groups to shrink - #21837
Merged
MrJul merged 4 commits intoJul 24, 2026
Merged
Conversation
Shared auto columns expand when grouped content becomes visible but keep the expanded width after that content is hidden. Cover the full zero, expanded, and shrunk layout sequence so the stale shared minimum cannot regress unnoticed.
Shared auto definitions reused the previous group minimum while recomputing the next group minimum, so an expanded width became self-sustaining after content shrank. Aggregate each definition's intrinsic measured minimum instead, preserving the shared-size invariant and matching the canonical WPF algorithm.
NathanDrake2406
marked this pull request as ready for review
July 23, 2026 16:26
|
You can test this PR using the following package version. |
MrJul
requested changes
Jul 24, 2026
MrJul
left a comment
Member
There was a problem hiding this comment.
This matches WPF, which has the same fix:
However, the fix also needs to change the cached min sizes (they seem to be used only in cyclic dependency cases, worth adding a test?):
dotnet/wpf@1dc9add#diff-2118bc4fdd6a3c621f56e0951cb2595b6ebc330df938e8750e100e08815b4e8e
A grid mixing an auto-column/star-row cell with a star-column/auto-row cell measures through Grid's cyclic dependency path, which saves and restores definition min sizes around the repeated measure. The saved value is the effective min size, so the group minimum is folded into the definition's own contribution and the group can never shrink below it.
Grid.CacheMinSizes read DefinitionBase.MinSize, which already includes the shared group's minimum, but ApplyCachedMinSizes writes it back through SetMinSize, which assigns the definition's own _minSize. A short-pole definition therefore adopted the group minimum as its own intrinsic minimum, which reclassified it as a long pole on the next validation. Long poles with a valid measure are never remeasured, so the fabricated minimum became unreachable and pinned the group open. Add DefinitionBase.RawMinSize, the read counterpart of SetMinSize, and cache that instead so the save/restore pair round-trips the definition's own contribution. Matches the WPF fix in dotnet/wpf#2270.
3 tasks
|
You can test this PR using the following package version. |
MrJul
pushed a commit
that referenced
this pull request
Jul 29, 2026
* test(grid): reproduce shared size group shrink failure Shared auto columns expand when grouped content becomes visible but keep the expanded width after that content is hidden. Cover the full zero, expanded, and shrunk layout sequence so the stale shared minimum cannot regress unnoticed. * fix(grid): allow shared size groups to shrink Shared auto definitions reused the previous group minimum while recomputing the next group minimum, so an expanded width became self-sustaining after content shrank. Aggregate each definition's intrinsic measured minimum instead, preserving the shared-size invariant and matching the canonical WPF algorithm. * test(grid): reproduce shared size group stuck on cyclic measure path A grid mixing an auto-column/star-row cell with a star-column/auto-row cell measures through Grid's cyclic dependency path, which saves and restores definition min sizes around the repeated measure. The saved value is the effective min size, so the group minimum is folded into the definition's own contribution and the group can never shrink below it. * fix(grid): restore raw min sizes on the cyclic measure path Grid.CacheMinSizes read DefinitionBase.MinSize, which already includes the shared group's minimum, but ApplyCachedMinSizes writes it back through SetMinSize, which assigns the definition's own _minSize. A short-pole definition therefore adopted the group minimum as its own intrinsic minimum, which reclassified it as a long pole on the next validation. Long poles with a valid measure are never remeasured, so the fabricated minimum became unreachable and pinned the group open. Add DefinitionBase.RawMinSize, the read counterpart of SetMinSize, and cache that instead so the save/restore pair round-trips the definition's own contribution. Matches the WPF fix in dotnet/wpf#2270.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
Allows synchronized
Griddefinitions in aSharedSizeGroupto shrink when the content that established the group minimum becomes smaller or hidden, fixing #21562.What is the current behavior?
Shared auto columns expand when grouped content grows, but retain that width after the content is hidden. During deferred validation, the group minimum is recomputed through
DefinitionBase.MinSize, which includes the previous shared minimum. The old maximum therefore feeds back into the next calculation and becomes self-sustaining.What is the updated/expected behavior with this PR?
Shared definitions continue to expand together and now shrink together after their intrinsic measured minimum decreases.
Validation on macOS ARM64 with .NET 10:
Shared_Size_Group_Shrinks_When_Content_Is_Hidden, covering the initial, expanded, and shrunk states across the deferred shared-size layout cycle.GridTests: 80 passed, 0 failed.Avalonia.Controls.UnitTestsexecutable: 3,649 total, 3,648 passed, 1 pre-existing skipped, 0 failed.How was the solution implemented (if it's not obvious)?
Deferred shared-size validation now aggregates each definition's intrinsic measured
_minSizeinstead of its effectiveMinSize, which can include the group minimum from the previous layout cycle. This restores the existing long-pole/short-pole invariant and matches the canonical WPF shared-size algorithm.The commits follow the repository's bug-fix convention: the first commit adds the failing behavioral test, and the second commit contains the fix.
Checklist
Breaking changes
None. This restores the expected
SharedSizeGroupshrink behavior without changing public API.Obsoletions / Deprecations
None.
Fixed issues
Fixes #21562