C
C#9mo ago
Lamp

MudBlazor darkmode toggle not working

I just want to check system preferences on load for the theme, but also allow the user to change from dark to light mode whenever they want. The toggle just doesn't work. I click on it and nothing happens. @inherits LayoutComponentBase <MudThemeProvider @ref="@provider" @bind-IsDarkMode="@useDarkMode" /> <MudDialogProvider /> <MudSnackbarProvider /> <MudLayout> <MudAppBar Elevation="1">
<MudText Typo="Typo.h5" Class="ml-3">[Text Here]</MudText> <MudSpacer/> <MudSwitch @bind-Value="useDarkMode" Color="Color.Primary" Class="ma-4" T="bool" Label="Toggle Light/Dark Mode" /> <MudIconButton Icon="@Icons.Material.Filled.MoreVert" Color="Color.Inherit" Edge="Edge.End"/> </MudAppBar> <MudMainContent> @Body </MudMainContent> </MudLayout> @code { private bool useDarkMode; private MudThemeProvider provider; protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { useDarkMode = await provider.GetSystemPreference(); await provider.WatchSystemPreference(OnSystemPreferenceChanged); StateHasChanged(); } } private async Task OnSystemPreferenceChanged(bool newValue) { useDarkMode = newValue; StateHasChanged(); } }
11 Replies
Anu6is
Anu6is9mo ago
which .net version are you using?
Lamp
Lamp9mo ago
.net8 with interactive auto does that mean my whole layout has to go in the .Client project if i want interactivity in it? <HeadOutlet @rendermode="InteractiveServer" /> <Routes @rendermode="InteractiveServer" /> i changed those by adding the @rendermode tag but I'm not sure that's what I want to be doing.
Anu6is
Anu6is9mo ago
so did taht allow it to work?
Lamp
Lamp9mo ago
yes it did
Anu6is
Anu6is9mo ago
yeah, that should make the entire app interactive server idk if that's what u want or not
Lamp
Lamp9mo ago
haha yea i want to have it be interactive auto so ig i move the layout to the Client project will there be any side effects to that?
Anu6is
Anu6is9mo ago
haven't really messed with auto myself so can't say try it an see...just monitor what is being downloaded
Lamp
Lamp9mo ago
wait so for interactive auto... is everything that's not in the Client app static SSR??
Anu6is
Anu6is9mo ago
as far as i'm aware it should be interactive server side
Lamp
Lamp9mo ago
wait so then why doesnt the toggle work
Anu6is
Anu6is9mo ago
¯\_(ツ)_/¯
Want results from more Discord servers?
Add your server