WebMap for Blazor
  • WebMap Blazor
    • Modernization
      • Overview
      • Modernization Challenges
      • Our solution
      • What is Blazor?
      • How does Blazor Work?
      • Windows Forms in Blazor
      • Deployment
      • Interfacing with hardware devices
    • Research for Blazor
      • Handling Reference Parameters in Async Methods with Ref<T>
      • Alternatives to Async Properties in C#
      • Issue with using "MessageBox.Show" in Blazor
      • File Upload Functionality
      • Async/Await Feature for WebMap Blazor
    • Assessment Tool
    • Conversion Tool
      • Getting Started
      • Modals and Dialogs
      • Static Service Management
      • ImageListStreamer
      • Solution and Project Structure
        • Solution Generator
    • DCP: Desktop Compatibility Library
      • API Documentation
        • Blazor DCP: Gap.Blazor.Application Class Reference
      • Components Information
        • Button Component
        • Application Data Component
        • GroupBox Component
        • Label Component
        • CheckBox
        • CheckedListBox
        • ComboBox
        • DateTimePicker
        • Form
        • ListBox
        • ListView
          • WMListViewDetails
        • Mdi Container Component
        • MenuStrip
        • MessageBox
        • MonthCalendar
        • Panel
        • PictureBox
        • ProgressBar
        • RadioButton
        • StatusStrip
        • ToolStripStatusLabel
        • TabControl
        • TabPage
        • TextBox
        • ToolStrip
          • ToolStripButton
          • ToolStripLabel
          • ToolStripSeparator
        • ToolTip
    • Post Conversion
      • How To?
        • Create a new WebMap Window?
        • Create a new WebMap Component?
        • Create a native Blazor Window in a WebMap app?
        • Create a native Blazor Component in a WebMap Window?
        • Change the default WebMap visual layout?
    • WebMap: Angular vs Blazor
      • Footprint
      • Binaries size
      • Chatiness
      • Performance
      • Extensibility
      • Maintainability
      • Debugging
      • Project Structure
    • WebMap for Blazor Release Notes
      • Beta version
    • FAQ
    • Errors and Troubleshooting
    • License
Powered by GitBook
On this page
  • Description
  • Usage
  • Properties
  • MenuItem Class
  • Methods
  • Dynamic Rendering
  • Styles
  • Events
Export as PDF
  1. WebMap Blazor
  2. DCP: Desktop Compatibility Library
  3. Components Information

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.MenuStrip model.

  • menuItems: A list of MenuItem objects representing the menu hierarchy.

MenuItem Class

public class MenuItem
{
    public string Text { get; set; }
    public List<MenuItem>? SubItems { get; set; }
    public ToolStripItem ToolStripItem { get; set; }

    public MenuItem()
    {
        Text = string.Empty;
        ToolStripItem = new ToolStripItem();
    }
}

Methods

  • OnInitialized(): Subscribes to the Click event and builds the menu structure from the model.

  • buildMenuList(ToolStripItemCollection): Recursively constructs the top-level menu items.

  • buildMenuItem(ToolStripItem): Converts a ToolStripItem into a MenuItem, including subitems if present.

  • buildSubItems(ToolStripItemCollection): Recursively builds nested submenus.

  • OnClickHandler(MenuItem): Executes the PerformClick() method on the associated ToolStripItem.

  • GetBackColorHex(): Returns the background color in hex format, defaulting to #FDFDFDFF if 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 SubItems property.

Styles

.@model.GetComponentClass() {
    background-color: [model.BackColor] !important;
    color: [model.ForeColor] !important;
}

.@model.GetComponentClass().k-menu {
    height: fit-content;
    width: 100%;
    z-index: 1;
}

.@model.GetComponentClass().k-menu li {
    color: inherit !important;
}

Events

  • Click: Triggered when a menu item is clicked, invoking the associated ToolStripItem.PerformClick().

PreviousMdi Container ComponentNextMessageBox

Last updated 2 days ago