MenuStrip
Description
This component represents a menu strip in Blazor using the Gap.Blazor.MenuStrip model. It renders a hierarchical menu using the Telerik Menu component and dynamically builds the menu structure from a ToolStripItemCollection. It supports nested submenus and click event handling for each item.
Usage
@inherits WMControlComponentBase
@namespace Gap.Blazor.Components
<WMStyleBase model=@this.menuStrip></WMStyleBase>
<TelerikMenu Class=@this.menuStrip.GetStringClasses()
Data=@this.menuItems
ItemsField="SubItems"
TextField="Text"
OnClick="@((MenuItem item) => OnClickHandler(item))">
</TelerikMenu>
<style>
.@model.GetComponentClass() {
background-color: @GetBackColorHex() !important;
color: @menuStrip.GetForeColorHex() !important;
}
.@(model.GetComponentClass()+".k-menu") {
height: fit-content;
width: 100%;
z-index: 1;
}
.@(model.GetComponentClass()+".k-menu") li {
color: inherit !important;
}
</style>
Properties
menuStrip: Instance of the
Gap.Blazor.MenuStripmodel.menuItems: A list of
MenuItemobjects representing the menu hierarchy.
MenuItem Class
Methods
OnInitialized(): Subscribes to the
Clickevent and builds the menu structure from the model.buildMenuList(ToolStripItemCollection): Recursively constructs the top-level menu items.
buildMenuItem(ToolStripItem): Converts a
ToolStripIteminto aMenuItem, including subitems if present.buildSubItems(ToolStripItemCollection): Recursively builds nested submenus.
OnClickHandler(MenuItem): Executes the
PerformClick()method on the associatedToolStripItem.GetBackColorHex(): Returns the background color in hex format, defaulting to
#FDFDFDFFif not set.
Dynamic Rendering
TelerikMenu: Renders the menu UI with support for nested items.
Dynamic Styling: Background and text colors are derived from the model.
Submenus: Automatically rendered based on the
SubItemsproperty.
Styles
Events
Click: Triggered when a menu item is clicked, invoking the associated
ToolStripItem.PerformClick().
Last updated