From 249afe95f1f5a0387750b735ccbc41c1b6a6ac7a Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Wed, 1 Jun 2022 12:06:38 +0300 Subject: [PATCH 1/2] Add MenuItemName to PageLayout for blazor --- .../Layout/PageLayout.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageLayout.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageLayout.cs index 618445bd83..3edbb9dc45 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageLayout.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageLayout.cs @@ -1,5 +1,6 @@ using System.Collections.ObjectModel; using System.ComponentModel; +using System.Runtime.CompilerServices; using Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars; using Volo.Abp.BlazoriseUI; using Volo.Abp.DependencyInjection; @@ -11,19 +12,32 @@ public class PageLayout : IScopedDependency, INotifyPropertyChanged private string title; // TODO: Consider using this property for setting Page Title too. - public virtual string Title - { + public virtual string Title { get => title; - set - { + set { title = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Title))); + OnPropertyChanged(); } } + private string menuItemName; + + public string MenuItemName { + get => menuItemName; + set { + menuItemName = value; + OnPropertyChanged(); + } + } + public virtual ObservableCollection BreadcrumbItems { get; set; } = new(); public virtual ObservableCollection ToolbarItems { get; set; } = new(); public event PropertyChangedEventHandler PropertyChanged; + + protected void OnPropertyChanged([CallerMemberName]string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } \ No newline at end of file From 1a6c44d3abe2a9165b598ed0aa68d780c6f680b5 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Wed, 1 Jun 2022 12:18:11 +0300 Subject: [PATCH 2/2] Update PageLayout documentation for MenuItemName --- docs/en/UI/Blazor/Page-Layout.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/en/UI/Blazor/Page-Layout.md b/docs/en/UI/Blazor/Page-Layout.md index 61d91d66af..49ed1659f4 100644 --- a/docs/en/UI/Blazor/Page-Layout.md +++ b/docs/en/UI/Blazor/Page-Layout.md @@ -13,6 +13,37 @@ Title is used to render page title in the PageHeader. } ``` +## MenuItemName +Indicates current selected menu item name. Menu item name should match a unique menu item name defined using the [Navigation / Menu system](../Blazor/Navigation-Menu.md). In this case, it is expected from the theme to make the menu item "active" in the main menu. + +```csharp +@inject PageLayout PageLayout + +@code { + protected override async Task OnInitializedAsync() + { + PageLayout.MenuItemName = "MyProjectName.Products"; + } +} +``` + +Menu item name can be set on runtime too. + +```html +@inject PageLayout PageLayout + + + +@code{ + protected void SetCategoriesMenuAsSelected() + { + PageLayout.MenuItemName = "MyProjectName.Categories"; + } +} +``` + +> Be aware, The [Basic Theme](../Blazor/Basic-Theme.md) currently doesn't support the selected menu item since it is not applicable to the top menu. + ## BreadCrumbs BreadCrumbItems are used to render breadcrumbs in the PageHeader. ```csharp