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.

NavigationViewItems created dynamically via MenuItemsSource crash under More dropdown

See original GitHub issue

Describe 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:open
  • Created 5 years ago
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
ojhadcommented, Mar 16, 2021

@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.

1reaction
licanhuacommented, Aug 20, 2020

@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:

        <Grid.Resources>
            <local:Customers x:Key="customers"/>
            <DataTemplate x:Key="NavigationItemTemplate">
                <mux:NavigationViewItem Content="{Binding linkTitle}" Icon="{Binding linkImage}" Tag="{Binding Id}"/>
           </DataTemplate>
        </Grid.Resources>
        <mux:NavigationView MenuItemsSource="{StaticResource customers}" PaneDisplayMode="Top" MenuItemTemplate="{StaticResource NavigationItemTemplate}"></mux:NavigationView>
 
   public class Customer
    {
        public string linkTitle { get; set; }
        public IconElement linkImage { get; set; }
 
        public Customer(string title, SymbolIcon iconElement)
            {
            linkTitle = title;
            linkImage = iconElement;
            }
    }
 
    public class Customers : ObservableCollection<Customer>
    {
        public Customers()
        {
            Add(new Customer("1111111111111", new SymbolIcon(Symbol.Accept)));
            Add(new Customer("2222222222222", new SymbolIcon(Symbol.Accept)));
            Add(new Customer("1333333333333333333333", new SymbolIcon(Symbol.Accept)));
            Add(new Customer("44444444444444", new SymbolIcon(Symbol.Accept)));
        }
 
    }

Read more comments on GitHub >

github_iconTop 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 >

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