microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.36k stars 679 forks source link

NVI.IsSelected is ignored in hierarchical NavigationView for unrealized items #3149

Open marcelwgn opened 4 years ago

marcelwgn commented 4 years ago

Describe the bug

Steps to reproduce the bug

Create a NV with hierarchical NVI defined in XAML and set IsSelected to true on one of the child items. In the loaded event handler of that NV, observe how SelectedItem is null.

This behavior is also present when setting the IsSelected property later, as long as the item has not been rendered.

Expected behavior

The NV should know that one of it's children where selected. Screenshots

Version Info

NuGet package version:

latest commit

Windows app type: UWP Win32
Windows 10 version Saw the problem?
Insider Build (xxxxx) Yes
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

marcelwgn commented 4 years ago

Copying @ranjeshj from #3015 for context: We will only update selection with items whose IsSelected property was set when they are visible in the VisualTree. The order would be: latest item loaded wins.

@anawishnoff @YuliKl FYI.

tuggernuts commented 2 years ago

Hi, is there any progress with this issue? I am experiencing a lot of difficulty in programmatically updating the hierarchy, and I think it is this issue. (WinUI3 in Desktop, SDK 1.0)

  1. if i create a new NVI (via datatemplate), I have to wait to select until NVI loaded event
  2. if i remove that NVI, then re-add via datatemplate,, I no longer have access to NVI loaded event...because NVI is recycled?
  3. I have resorted to a timer that selects items after they have been added to hierarchy

If this doesn't make sense, I can create a sample repo. I added a sample repo https://github.com/tuggernuts/NavViewTestApp

Also, is there a workaround I'm missing @chingucoding @StephenLPeters

marcelwgn commented 1 year ago

Bump for #8638 since this is still an issue.

ranjeshj commented 1 year ago

@chingucoding would you be able to attach a repro app please ? The link above does not work and might not be the same issue as the primary bug.

marcelwgn commented 1 year ago

Sorry for the delayed response, this must have flown past. Attached project repros the issue. App1.zip My guess would be that unrealized items don't actually get created and as such don't register to the NavigationView. Because of that, the NavigationView in turn doesn't know about the existence of that item or its selection.