NavigationViewItems created dynamically via MenuItemsSource crash under More dropdown
See original GitHub issueDescribe the bug When creating items dynamically via a bound collection with MenuItemsSource using a MenuItemTemplate. It will work as expected until the top menu is compressed enough to move items under the “More” dopdown menu. When it does, expanding the menu will create the following error:
Failed to assign to property ‘Windows.UI.Xaml.Controls.ContentPresenter.Content’. [Line: 6980 Position: 37]
and crash. If done statically, they work as expected.
Steps to reproduce the bug Bind the MenuItemsSource to a collection.
Use a DataTemplate
<DataTemplate x:Key="NavigationItemTemplate">
<mux:NavigationViewItem Content="{Binding linkTitle}" Icon="{Binding linkImage}" Tag="{Binding Id}"/>
</DataTemplate>
Expected behavior The menu shows correctly
Version Info
NuGet package version: 2.1.181217001-prerelease
Windows 10 version:
- October 2018 Update (17763)
Device form factor:
- Desktop
- Mobile
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (13 by maintainers)
Top Results From Across the Web
UWP XAML dynamically add Navigation View items using ...
Looking into creating a way to dynamically add navigation view items either using a page with drop downs or flyout menu and didn't...
Read more >Dynamically binding NavigationViewItem && ...
I want to populate NavigationViewItem s and NavigationViewItemHeader s dynamically in my NavigationView . However, I can not make it work. It ...
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 Free
Top 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
@StephenLPeters Based on the investigation above and what I am seeing, it looks like the removal/addition of items may be happening in
NavigationView::HandleTopNavigationMeasureOverrideOverflow
. More specifically this part of the function does not look like its behaving as intended in order to avoid NavigationView determining that all the items can be re-added to the top nav. Seems like the item width state is not being saved properly for the line linked above to do its job.@chingucoding It’s hard for you to debug it without the source code from Xaml. It’s possible a bug from platform, and most likely Icon property trigged the problem. @ranjeshj I forwarded the email about my investigation before.
Here is the code I used to repro the problem: