Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Update AppBarText in MudBlazor

$
0
0

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;    }}

enter image description here

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>

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>