Lepton - Implementation of MenuItemName #10562
- Depends on https://github.com/abpframework/abp/pull/12840
- Closes #10052
Example & Test
I've a page with route /products/{Name}/{Model}
, and that page sets the MenuItemName as Products
protected override Task OnInitializedAsync()
{
PageLayout.MenuItemName = MenuProducts;
return base.OnInitializedAsync();
}
Setup
And also selected menu items can be changed at runtime.
Menu Contributor
context.Menu.Items.Insert( 1, new ApplicationMenuItem( "MyProjectName.Products", "Products", "/products", icon: "fas fa-circle" )); context.Menu.Items.Insert( 1, new ApplicationMenuItem( "MyProjectName.A", "Menu A", "#a", icon: "fas fa-square" )); context.Menu.Items.Insert( 1, new ApplicationMenuItem( "MyProjectName.B", "Menu B", "#b", icon: "fas fa-plus" ));
Razor page:
@page "/products/{Name}/{Model}" @inject Volo.Abp.AspNetCore.Components.Web.Theming.Layout.PageLayout PageLayout <h1>Products Page</h1> <ul> <li><b>Name: </b> @Name</li> <li><b>Model: </b> @Model</li> </ul> <Button Clicked="(()=> ChangeMenu(MenuProducts))">Change Menu (Products) </Button> <Button Clicked="(()=> ChangeMenu(MenuA))">Change Menu (A) </Button> <Button Clicked="()=>ChangeMenu(MenuB)">Change Menu (B) </Button>
And the class:
public partial class ProductsPage { [Parameter] public string Name { get; set; } [Parameter] public string Model { get; set; } const string MenuProducts = "MyProjectName.Products"; const string MenuA = "MyProjectName.A"; const string MenuB = "MyProjectName.B"; protected override Task OnInitializedAsync() { PageLayout.MenuItemName = MenuProducts; return base.OnInitializedAsync(); } protected void ChangeMenu(string menuName) { Console.WriteLine("ChangeMenu: " + menuName); PageLayout.MenuItemName = menuName; } }