Implement dark mode support using a new ThemeState service that manages theme switching and integrates with DevExpress Blazor theming. Update App.razor to apply the theme globally, enhance MainLayout with a toggle button and dynamic CSS classes, and add dark mode styles to CSS files. Register ThemeState as a scoped service in Program.cs.
44 lines
1022 B
Plaintext
44 lines
1022 B
Plaintext
@inherits LayoutComponentBase
|
|
@implements IDisposable
|
|
@inject ThemeState ThemeState
|
|
|
|
<div class="page @(ThemeState.IsDarkMode ? "app-dark" : "app-light")">
|
|
<div class="sidebar">
|
|
<NavMenu />
|
|
</div>
|
|
|
|
<main>
|
|
<div class="top-row px-4">
|
|
<DxButton Text="@(ThemeState.IsDarkMode ? "Dark Mode aus" : "Dark Mode an")" Click="ToggleTheme" />
|
|
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
|
|
</div>
|
|
|
|
<article class="content px-4">
|
|
@Body
|
|
</article>
|
|
</main>
|
|
</div>
|
|
|
|
<div id="blazor-error-ui">
|
|
An unhandled error has occurred.
|
|
<a href="" class="reload">Reload</a>
|
|
<a class="dismiss">🗙</a>
|
|
</div>
|
|
|
|
@code {
|
|
protected override void OnInitialized()
|
|
{
|
|
ThemeState.OnChange += StateHasChanged;
|
|
}
|
|
|
|
private void ToggleTheme()
|
|
{
|
|
ThemeState.SetDarkMode(!ThemeState.IsDarkMode);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
ThemeState.OnChange -= StateHasChanged;
|
|
}
|
|
}
|