3

I want to create a HamburgerMenu from a dynamic list of items, preferably I'd like to bind something like a ListBox with a template to a list on my view model, and have the menu items appear dynamically. (See: http://bit.ly/1Lac78E).

Attempting to add anything to the PrimaryButtons (or probably the SecondaryButtons) collection other than HamburgerButtonInfo causes an error. Presumably because those collections are declared as:

PrimaryButtons = new ObservableItemCollection<HamburgerButtonInfo>(); 
SecondaryButtons = new ObservableItemCollection<HamburgerButtonInfo>(); 

So is it possible to do this with the Template10 hamburger menu, without using code-behind like in this question: UWP Template 10 create a dynamic hamburgermenu?

UPDATE

To clarify, I am trying to create a navigation menu (using the Hamburger menu template) similar to the Mail and Calendar app, where there is a dynamic list of folders and items in the folders.

enter image description here

Community
  • 1
  • 1
CodingGorilla
  • 19,612
  • 4
  • 45
  • 65

1 Answers1

1

First, I am not sure this is very smart in the first place.

But here's how you can do it.

public class MainPage:Page
{
    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        ViewModel.PrimaryButtons = Views.Shell.HamburgerMenu.PrimaryButtons;
        ViewModel.SecondaryButtons = Views.Shell.HamburgerMenu.SecondaryButtons;
    }
}

public class MainPageViewModel
{
    Windows.Foundation.Collections.IObservableVector<ICommandBarElement> PrimaryButtons { get; set; }
    Windows.Foundation.Collections.IObservableVector<ICommandBarElement> SecondaryButtons { get; set; }
}

Best of luck, Jerry

Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
  • 1
    Why do you say it's not very smart? – CodingGorilla Mar 08 '16 at 13:25
  • I did a dynamic appbar for uwp but I don't have time for now to share the code I'll try to do that tonight – RicardoPons Mar 08 '16 at 16:06
  • So this causes a compiler error `Cannot implicitly convert type 'System.Collections.ObjectModel.ObservableCollection' to 'System.Collections.ObjectModel.ObservableCollection'. Trying to cast it, just gives me a different compiler error telling me that it's not castable. – CodingGorilla Mar 09 '16 at 16:10
  • @RicardoPons To be clear I want to add items to the hamburger (nav menu) down the right side, not the app bar. Essentially I want to create something similar to the Mail and Calendar app, where the items in the hamburger menu are a set of folders and items in the folders. Depending on the user (like in Mail and Calendar) the number and names of folders will be different. – CodingGorilla Mar 09 '16 at 16:23