HamburgerMenuNavigationButton Class
Represents a button with an icon in the Main Menu of the HamburgerMenu that navigates to the specified page with a click.
Namespace: DevExpress.Xpf.WindowsUI
Assembly: DevExpress.Xpf.Controls.v24.1.dll
NuGet Package: DevExpress.Wpf.Controls
Declaration
Remarks
The HamburgerMenuNavigationButton
represents a button in the HamburgerMenu. To add a button to the HamburgerMenu, use the menu’s HamburgerMenu.Items collection, or declare buttons between the HamburgerMenu‘s opening and closing tags.
The example below illustrates how to specify a template for the HamburgerMenuNavigationButton
based on the MVVM design pattern.
<DataTemplate DataType="{x:Type local:HamburgerNavigationItemViewModel}">
<dxwui:HamburgerMenuNavigationButton Content="{Binding Content}"
Glyph="{Binding Icon}"
dxb:ImageColorizer.IsEnabled="True"
GlyphWidth="24"
GlyphHeight="24"
dxb:ImageColorizer.Color="{Binding Foreground.Color, RelativeSource={RelativeSource Self}}"
Placement="{Binding Placement}"
HideMenuWhenSelected="{Binding HideMenuWhenSelected}"
SelectOnClick="{Binding SelectOnClick}"
Command="{Binding Command}"
CommandParameter="{Binding CommandParameter}"
NavigationTargetType="{Binding NavigationTargetType}" />
</DataTemplate>
public class HamburgerNavigationItemViewModel : HamburgerItemWithCommand {
bool _hideMenuWhenSelected = false;
bool _selectOnClick = true;
public bool HideMenuWhenSelected {
get { return _hideMenuWhenSelected; }
set { SetProperty(ref _hideMenuWhenSelected, value, "HideMenuWhenSelected"); }
}
public bool SelectOnClick {
get { return _selectOnClick; }
set { SetProperty(ref _selectOnClick, value, "SelectOnClick"); }
}
public HamburgerNavigationItemViewModel(object content, string icon, Type navigationTargetType, ICommand command = null) {
Content = content;
Icon = GetIconUriFromName(icon);
NavigationTargetType = navigationTargetType;
Command = command;
}
}
public abstract class HamburgerItemWithCommand : HamburgerItemViewModelBase {
ICommand _command = null;
object _commandParameter = null;
public ICommand Command {
get { return _command; }
set { SetProperty(ref _command, value, "Command"); }
}
public object CommandParameter {
get { return _commandParameter; }
set { SetProperty(ref _commandParameter, value, "CommandParameter"); }
}
}
public abstract class HamburgerItemViewModelBase : BindableBase {
Type _navigationTargetType = null;
object _content = null;
Uri _icon = null;
HamburgerMenuItemPlacement _placement = HamburgerMenuItemPlacement.Top;
public Type NavigationTargetType {
get { return _navigationTargetType; }
set { SetProperty(ref _navigationTargetType, value, "NavigationTargetType"); }
}
public object Content {
get { return _content; }
set { SetProperty(ref _content, value, "Content"); }
}
public Uri Icon {
get { return _icon; }
set { SetProperty(ref _icon, value, "Icon"); }
}
public HamburgerMenuItemPlacement Placement {
get { return _placement; }
set { SetProperty(ref _placement, value, "Placement"); }
}
public HamburgerItemViewModelBase() {
Placement = HamburgerMenuItemPlacement.Top;
}
internal static Uri GetIconUriFromName(string name) {
if(string.IsNullOrEmpty(name))
return null;
return new Uri(string.Format("pack://application:,,,/WindowsUIDemo;component/Images/Hamburger/{0}.png", name), UriKind.Absolute);
}
}
When an end-user clicks or taps the button, the application navigates to the associated target page. You specify the target page using the NavigationTargetType
or NavigationTargetTypeName
property. The NavigationTargetParameter
property specifies the navigation parameter to pass to the target page.
The HamburgerMenuNavigationButton
is a content control. Typically, you specify a string caption using the button’s Content
property. However, you can use custom objects to specify the button content and use the ContentTemplate
property to visualize the content.