You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
#4459
Open
montanarispark opened this issue
Jan 23, 2024
· 0 comments
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:
<DataTemplate DataType="{x:Type mah:HamburgerMenuIconItem}">
<Expander x:Name="ExpanderPart"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
BorderThickness="0"
FlowDirection="RightToLeft"
mah:HeaderedControlHelper.HeaderBackground="Transparent"
mah:HeaderedControlHelper.HeaderForeground="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:HamburgerMenu}}, Path=PaneForeground}"
>
<Expander.Header>
<DockPanel Height="48" LastChildFill="True" Background="Transparent"
FlowDirection="LeftToRight">
<ContentControl x:Name="IconPart"
Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:HamburgerMenu}}, Path=CompactPaneLength}"
Content="{Binding Icon}"
DockPanel.Dock="Left"
Focusable="False"
IsTabStop="False">
</ContentControl>
<TextBlock VerticalAlignment="Center"
FontSize="16"
Text="{Binding Label}" />
</DockPanel>
</Expander.Header>
<mah:HamburgerMenuListBox ItemsSource="{Binding Tag}"
Margin="0,0,10,0"
FlowDirection="LeftToRight"
HorizontalAlignment="Stretch"
Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:HamburgerMenu}}, Path=PaneForeground}"
IsTextSearchEnabled="True"
ItemContainerStyleSelector="{StaticResource HamburgerMenuItemStyleSelector}"
ItemTemplateSelector="{DynamicResource MenuItemTemplateSelector}"
SelectionMode="Single"
/>
</Expander>
</DataTemplate>
You can then insert the submenu items in the tag property:
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<object, bool> _canExecute;
private readonly Action<object> _execute;
public DelegateCommand(Action<object> execute) : this(execute, s => true)
{
}
public DelegateCommand(Action<object> execute, Func<object, bool> 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
The text was updated successfully, but these errors were encountered:
You can then insert the submenu items in the tag property:
This is what the result looks like:
Originally posted by @derSteff18 in #3018 (comment)
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:
.
.
.
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
The text was updated successfully, but these errors were encountered: