Skip to content

NavigationViewItem::PrepNavigationViewItem: use XAML weak references - #12235

Merged
Abhijeet Jha (iamAbhi-916) merged 1 commit into
mainfrom
user/abhijeetjha/navview-dynamic-items-10757
Oct 12, 2026
Merged

Abhijeet Jha (iamAbhi-916) merged 1 commit into
mainfrom
user/abhijeetjha/navview-dynamic-items-10757

Conversation

@iamAbhi-916

@iamAbhi-916 Abhijeet Jha (iamAbhi-916) commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-triage Issue needs to be triaged by the area owners

Projects

None yet

3 participants