NavigationView.MenuItems not populated when using NavigationView.ItemsSource
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
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 ?