question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NavigationView.MenuItems not populated when using NavigationView.ItemsSource

See original GitHub issue

Describe the bug

If I bind the to NavigationView.ItemsSource and use DataTemplate like below, I am not able to see any items in NavigationView.MenuItems.

Steps to reproduce the bug

Steps to reproduce the behavior:

    <winui:NavigationView
        x:Name="NavigationView"
        x:Uid="Settings_Title" IsPaneToggleButtonVisible="False"
        PaneDisplayMode="LeftCompact" CompactModeThresholdWidth="0"
        IsSettingsVisible="False"
        IsBackButtonVisible="Collapsed"
        Background="{ThemeResource SystemControlBackgroundAltHighBrush}">
        <winui:NavigationView.MenuItemTemplate>
            <DataTemplate x:DataType="models:IRepository">
                <winui:NavigationViewItem Content="{x:Bind Name}">
                    <winui:NavigationViewItem.Icon>
                        <FontIcon x:Name="OptionIcon" Grid.RowSpan="2" FontFamily="Segoe MDL2 Assets" Glyph="{x:Bind Icon}" FontSize="40" />
                    </winui:NavigationViewItem.Icon>
                </winui:NavigationViewItem>
            </DataTemplate>
        </winui:NavigationView.MenuItemTemplate>

Expected behavior

MenuItems should still be populated

Screenshots

Version Info

NuGet package version: Microsoft.UI.Xaml 2.4.2

Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041)
November 2019 Update (18363) Yes
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
Xbox
Surface Hub
IoT

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
harvinderscommented, Jul 8, 2020

@StephenLPeters I was trying to migrating WTS generated code to use dynamic NavigationViewItems instead of the statically declared one. The logic there required that I iterate over the MenuItems. However, I realised that I don’t need that and I can achieve same using SelectedItem and ItemsSource.

1reaction
ranjeshjcommented, Jul 7, 2020

Curious why you need the TabItems ? Are you trying to get the NavigationViewItems when you have provided a collection to MenuItemsSource ? What if the items are virtualized ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

UWP: NavigationView.MenuItems results empty if ...
UWP: NavigationView.MenuItems results empty if populated programmatically. I can reproduce your problem that MenuItems.Count is zero.
Read more >
NavigationViewItem.MenuItemsSource Property
This example adds hierarchy by defining the item template to be a NavigationViewMenuItem, with its Content set to be the label of the...
Read more >
How-To: Use a NavigationView to Switch Views
Add the NavigationView.MenuItems collection to the NavigationView and add a NavigationViewItem for each view you want to navigate to. <NavigationView.
Read more >
WinUI 3 | XAML Brewer, by Diederik Krols | Page 2
It's often populated with a NavigationView menu and a Frame to host the different page types. Our sample app has a similar main...
Read more >
Hierarchical Data Binding - Telerik UI for WPF - Documentation
This article shows how to data bind hierarchical data to RadNavigationView. The control can be populated with business objects via its ItemsSource property....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found