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

46 lines
1.4 KiB
C#
Raw Permalink Normal View History

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
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();
LocalizationService.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()
{
LocalizationService.LanguageChanged -= OnLanguageChanged;
NavigationManager.LocationChanged -= OnLocationChanged;
}
2020-07-26 19:20:16 +08:00
}
}