I’m having a hard time getting this to work, and I’m hopelessly confused with all the templates one needs to use. Here’s the situation.
I want to have a menu dynamically created. The code takes a list of objects, groups the list, and then sets the itemsource of the menu.
navBarControl.NavBarMain.ItemsSource = newActions.GroupBy(Function(p) p.GroupName)
I need help with the templating and databinding in XAML. What I’m looking to happen is to have a menu created with the top items being the group key, and then the children for each key being the items themselves.
And then I need to have a click handler set for every child so that I can execute code on a menu item click.
This is proving to be difficult for me to accomplish. Can some one provide a XAML example of how this would work?
After some experimentation and a little luck I’ve finally found a solution. I hope this helps anyone else with this problem. To recap, I wanted to bind to a datasource (grouped), that has children (possibly grandchildren), and have the menu dynamically built. The challenge was routing ALL the menu item click events to a single event handler. Here’s what I came up with.
And here is the itemsource being set in the code. C# and VB respectively