Repository navigation
NavigationViewItem::PrepNavigationViewItem: use XAML weak references - #12235
Merged
Abhijeet Jha (iamAbhi-916) merged 1 commit intoOct 12, 2026
Merged
Abhijeet Jha (iamAbhi-916) merged 1 commit into
Abhijeet Jha (iamAbhi-916) merged 1 commit into
Conversation
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.
Description:
Prevent E_FAIL when collapsing or expanding NavigationView after dynamically replacing its items. Fixes #10757.
Root cause:
The SplitView property callbacks capture raw this and can reach removed items after reference-tracker GC has cleared their XAML weak references.
The reporter repro reaches NavigationViewItem::UpdateVisualStateForNavigationViewPositionChange -> GoToState with bReachable=false and bWeakReferenceDisconnected=true.
Fix:
Resolve a projected winrt::weak_refwinrt::NavigationViewItem before forwarding the three SplitView callbacks. This uses XAML's weak-reference source, rather than the implementation's independent get_weak(), and follows the existing projected-weak-reference pattern.
Behavior:
Live items retain pane, display-mode, and compact-length updates. GC-unreachable items are no longer called and no exceptions are swallowed.
Testing:
three removal-plus-GC cases fail with E_FAIL before the fix
all nine cases pass 40 cycles each afterward, preserving six baseline-green cases including hierarchy restoration, selection, item reuse, replacement, and reattachment.