Preserve bound actions during detach triggers - #369
Merged
Merged
Conversation
This was referenced Aug 21, 2026
This was referenced Aug 28, 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.
Summary
try/finally, even when a custom callback throwsRoot cause
The recent synchronous action-logical-tree cleanup exposed an ordering problem in
StyledElementBehavior:DetachedFromVisualTreeEventHandlerdetached the behavior/action logical treeDetachedFromVisualTreeTrigger.OnDetachedFromVisualTreeexecuted its actionsThe trigger itself still fired, but
InvokeCommandAction.Commandwas already null. This made the reported bound method/command appear not to run when switching tabs.The logical-tree detach path had the same ordering contract and is corrected alongside the visual path.
Changes
OnDetachedFromVisualTreebeforeDetachBehaviorFromLogicalTreeOnDetachedFromLogicalTreebefore releasing the same scopetry/finallyso parent, templated-parent, action lifecycle, and command observer cleanup still run if a consumer callback throwsTests
Reported regression
A compiled-XAML headless fixture mirrors the issue:
TabControlhosts aTextBlockDetachedFromVisualTreeTriggerInvokeCommandAction.Commandis compiled-bound from the window data contextThe regression test fails on current
masterand passes with this change.Cleanup safeguard
A behavior whose visual-detach callback throws verifies that logical parent and templated parent are still cleared.
Validation
Xaml.Behaviors.Interactivity.UnitTests: 94 passedXaml.Behaviors.Interactions.UnitTests: 90 passed, 2 pre-existing skippedgit diff --check: cleanCloses #353