I'm using MudBlazor to learn about the Blazor language. I have created a menu using MudAppBar.
MainLayout.razor
<MudThemeProvider /><MudPopoverProvider /><MudDialogProvider /><MudSnackbarProvider /><MudLayout><MudAppBar Color="Color.Primary" Fixed="true"><MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="DrawerToggle" /> @appBarText</MudAppBar><MudDrawer @bind-Open="@_drawerOpen" Anchor="Anchor.Left"><MudDrawerContainer><MudNavMenu Bordered="true"> <MudNavLink Href="" Match="NavLinkMatch.All" >Home</MudNavLink><MudNavLink Href="/counter" >Counter</MudNavLink><MudNavLink Href="fetchdata">FetchData</MudNavLink></MudNavMenu></MudDrawerContainer></MudDrawer><MudMainContent><MudContainer MaxWidth="MaxWidth.ExtraLarge"> @Body</MudContainer></MudMainContent></MudLayout>@code { bool _drawerOpen = true; private string appBarText = "Default AppBar Text"; private void UpdateAppBarText(string text) { appBarText = text; } private void DrawerToggle() { _drawerOpen = !_drawerOpen; }}The problem I'm having is that I can't change "appBarText" to the link title when I click on MudNavLink.
I created the function "UpdateAppBarText" and assigned it to the OnClick event on MudNavLink but it failed. Can anyone help me figure out which solution is best? Thank you everyone for your interest.
<MudNavMenu Bordered="true"> <MudNavLink Href="" Match="NavLinkMatch.All" OnClick="@(() => UpdateAppBarText("Home"))">Home</MudNavLink><MudNavLink Href="/counter" OnClick="@(() => UpdateAppBarText("Counter"))">Counter</MudNavLink><MudNavLink Href="/fetchdata" OnClick="@(()=> UpdateAppBarText("FetchData"))">FetchData</MudNavLink></MudNavMenu>
