ant-design-blazor/site/AntDesign.Docs/Shared/NavMenu.razor.cs

42 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.Globalization;
using System.Threading.Tasks;
2020-07-26 19:20:16 +08:00
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
2020-07-26 19:20:16 +08:00
namespace AntDesign.Docs.Shared
{
public partial class NavMenu : ComponentBase, IDisposable
2020-07-26 19:20:16 +08:00
{
protected override async Task OnInitializedAsync()
{
MenuItems = await DemoService.GetCurrentMenuItems();
LanguageService.LanguageChanged += OnLanguageChanged;
NavigationManager.LocationChanged += OnLocationChanged;
2020-07-26 19:20:16 +08:00
StateHasChanged();
await base.OnInitializedAsync();
}
private async void OnLanguageChanged(object sender, CultureInfo args)
{
MenuItems = await DemoService.GetCurrentMenuItems();
await InvokeAsync(StateHasChanged);
}
private async void OnLocationChanged(object sender, LocationChangedEventArgs args)
{
MenuItems = await DemoService.GetCurrentMenuItems();
StateHasChanged();
}
public void Dispose()
{
LanguageService.LanguageChanged -= OnLanguageChanged;
NavigationManager.LocationChanged -= OnLocationChanged;
}
2020-07-26 19:20:16 +08:00
}
}