MahApps / MahApps/MahApps.Metro

The HamburgerMenu control uses the HamburgerMenuListBox control to show the menu items. You can use a DataTemplate with an Expander control with an HamburgerMenuListBox control as the Child to show submenu items:

Open
#4,459 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
9.8k
Forks
2.4k
Avg merge
1h 2m
Merged PRs (30d)
56

Description

The HamburgerMenu control uses the HamburgerMenuListBox control to show the menu items. You can use a DataTemplate with an Expander control with an HamburgerMenuListBox control as the Child to show submenu items:












You can then insert the submenu items in the tag property:























This is what the result looks like:

![image](https://github.com/MahApps/MahApps.Metro/assets/94139245/655ae542-27a1-49db-9f9d-b751493d2957)

_Originally posted by @derSteff18 in https://github.com/MahApps/MahApps.Metro/issues/3018#issuecomment-1687413625_

I add subItems to the inner HamburgerMenuItemCollection dynamically from code behind. I set the Command for the sub-menu, but it isn't fired if I click the sub-menu. This is my code:

public partial class MainUC : UserControl
{
public MainUC()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
LoadPersonalizedTrend();
}
.
.
.

private void LoadPersonalizedTrend()
{
mnuTrendCollection.Clear();
HamburgerMenuGlyphItemForTrend mnu = new HamburgerMenuGlyphItemForTrend();
mnu.IsPersonalizedTrend = true;
mnu.Label = "Test 1";
mnu.Glyph = "ChartMultiple";
mnu.Command = new DelegateCommand(Execute);
mnuTrendCollection.Add(mnu);
}

private void Execute(object o)
{
MessageBox.Show("Hello");
}

}

public class DelegateCommand : ICommand
{
private readonly Func _canExecute;
private readonly Action _execute;

public DelegateCommand(Action execute) : this(execute, s => true)
{
}

public DelegateCommand(Action execute, Func canExecute)
{
_execute = execute;
_canExecute = canExecute;
}

public bool CanExecute(object parameter)
{
return _canExecute(parameter);
}

public void Execute(object parameter)
{
_execute(parameter);
}

public event EventHandler CanExecuteChanged;
}

If I do the same with a first level menu item it works. Itried also to use the ItemClick event, but it doesn't work for the subitems.

Thanks

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with HamburgerMenu, HamburgerMenuListBox, and a dynamically populated nested HamburgerMenuItemCollection. Trace how Command and ItemClick are handled for first-level and submenu items; done means commands or item-click events fire for dynamically added submenu items.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.