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
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);
}
}
Public Class HamburgerNavigationItemViewModel
Inherits HamburgerItemWithCommand
Private _hideMenuWhenSelected As Boolean = False
Private _selectOnClick As Boolean = True
Public Property HideMenuWhenSelected() As Boolean
Get
Return _hideMenuWhenSelected
End Get
Set(ByVal value As Boolean)
SetProperty(_hideMenuWhenSelected, value, "HideMenuWhenSelected")
End Set
End Property
Public Property SelectOnClick() As Boolean
Get
Return _selectOnClick
End Get
Set(ByVal value As Boolean)
SetProperty(_selectOnClick, value, "SelectOnClick")
End Set
End Property
Public Sub New(ByVal content As Object, ByVal icon As String, ByVal navigationTargetType As Type, Optional ByVal command As ICommand = Nothing)
Me.Content = content
Me.Icon = GetIconUriFromName(icon)
Me.NavigationTargetType = navigationTargetType
Me.Command = command
End Sub
End Class
Public MustInherit Class HamburgerItemWithCommand
Inherits HamburgerItemViewModelBase
Private _command As ICommand = Nothing
Private _commandParameter As Object = Nothing
Public Property Command() As ICommand
Get
Return _command
End Get
Set(ByVal value As ICommand)
SetProperty(_command, value, "Command")
End Set
End Property
Public Property CommandParameter() As Object
Get
Return _commandParameter
End Get
Set(ByVal value As Object)
SetProperty(_commandParameter, value, "CommandParameter")
End Set
End Property
End Class
Public MustInherit Class HamburgerItemViewModelBase
Inherits BindableBase
Private _navigationTargetType As Type = Nothing
Private _content As Object = Nothing
Private _icon As Uri = Nothing
Private _placement As HamburgerMenuItemPlacement = HamburgerMenuItemPlacement.Top
Public Property NavigationTargetType() As Type
Get
Return _navigationTargetType
End Get
Set(ByVal value As Type)
SetProperty(_navigationTargetType, value, "NavigationTargetType")
End Set
End Property
Public Property Content() As Object
Get
Return _content
End Get
Set(ByVal value As Object)
SetProperty(_content, value, "Content")
End Set
End Property
Public Property Icon() As Uri
Get
Return _icon
End Get
Set(ByVal value As Uri)
SetProperty(_icon, value, "Icon")
End Set
End Property
Public Property Placement() As HamburgerMenuItemPlacement
Get
Return _placement
End Get
Set(ByVal value As HamburgerMenuItemPlacement)
SetProperty(_placement, value, "Placement")
End Set
End Property
Public Sub New()
Placement = HamburgerMenuItemPlacement.Top
End Sub
Friend Shared Function GetIconUriFromName(ByVal name As String) As Uri
If String.IsNullOrEmpty(name) Then
Return Nothing
End If
Return New Uri(String.Format("pack://application:,,,/WindowsUIDemo;component/Images/Hamburger/{0}.png", name), UriKind.Absolute)
End Function
End Class
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 make use of the ContentTemplate property to visualize the content.
See Also