Fix AnchorLayoutV2 deferred anchor initialization when replacing anchored controls during suspended layout#14505
Open
LeafShi1 wants to merge 1 commit intodotnet:mainfrom
Conversation
…ored controls during suspended layout
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.
Fixes #14500
Root Cause
Under
AnchorLayoutV2, when an anchored control is replaced while its parent container is inside aSuspendLayout/ResumeLayoutflow, anchor metadata initialization can be deferred.During
ResumeLayout -> PerformLayout, the parent temporarily setsLayoutSuspendCountto 1 as part of its internal layout execution. The existing AnchorLayoutV2 logic treated that state the same as an externally suspended layout state, so the newly added anchored control could still skipAnchorInfoinitialization even though actual layout was already running.Proposed changes
AnchorInfofor anchored children immediately before anchored layout is applied, if that metadata is still missing.Panelat runtime and verifies that the replacement panel continues to resize with the form, inAnchorLayoutTests.cs.Customer Impact
AnchorLayoutV2that replace an anchored control at runtime inside aSuspendLayout / ResumeLayoutblock will have the replacement control resize correctly with the form. The manualAnchortoggle workaround is no longer needed.Regression?
Risk
Screenshots
Before
When using AnchorLayoutV2. resizing the window, one of the inner panels is resized incorrectly if replaced by an equivalent panel after the InitializeComponent().
BeforeChanges.mp4
After
Replaced anchored controls continue to resize correctly with the form.
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow