Fix CommandBar secondary visibility during overflow open - #21742
Merged
MrJul merged 1 commit intoJul 10, 2026
Merged
Conversation
NathanDrake2406
marked this pull request as ready for review
July 9, 2026 15:43
|
You can test this PR using the following package version. |
MrJul
pushed a commit
that referenced
this pull request
Jul 29, 2026
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?
Fixes a
CommandBaroverflow crash when a secondary command changesIsVisiblewhile the overflow popup is realizing its items.The scenario is reported in #21694: a
CommandBarButtoninCommandBar.SecondaryCommandscan updateIsVisiblefrom a binding as it is added to the popup'sItemsControl, which re-enters the command bar overflow rebuild.What is the current behavior?
Opening the overflow popup can throw:
InvalidOperationException: The control CommandBarButton already has a visual parent StackPanel while trying to add it as a child of StackPanel.The re-entrant visibility update clears and rebuilds
OverflowItemswhilePanelContainerGenerator.InsertContaineris still inserting the same control into the popup panel.What is the updated/expected behavior with this PR?
Opening the overflow popup no longer mutates
OverflowItemsduring the unsafe synchronous item-realization window. A visibility-triggered overflow rebuild is deferred until afterPopup.IsOpen = truereturns, then applied immediately so existing synchronous overflow state behavior is preserved outside that opening path.How was the solution implemented (if it's not obvious)?
CommandBarnow routes dynamic overflow rebuild requests through a small guard. While the overflow popup is synchronously opening, rebuild requests are marked as deferred. After the popup finishes opening, a single deferred rebuild is applied.A regression test covers a secondary command that changes
IsVisibleas it becomes parented by the overflow presenter, reproducing the same visual-parent collision path without depending on a particular binding engine timing detail.Checklist
Breaking changes
None.
Obsoletions / Deprecations
None.
Fixed issues
Fixes #21694
Verification
dotnet run --project tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj -- --filter-method "*Open_DoesNotThrow_WhenSecondaryCommandVisibilityChangesDuringOverflowRealization"dotnet run --project tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj -- --filter-class "Avalonia.Controls.UnitTests.CommandBar*"dotnet build src/Avalonia.Controls/Avalonia.Controls.csproj -p:AvsSkipBuildingLegacyTargetFrameworks=Truedotnet run --project tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj