@inherits LayoutComponentBase
@Body
@code {
public readonly MudTheme MudTheme = new MudTheme();
private MudThemeProvider? _themeProvider;
private bool _isDarkTheme = true;
public event EventHandler? OnDarkThemeChanged;
public bool DarkTheme
{
get => _isDarkTheme;
set
{
_isDarkTheme = value;
ThemeChanged();
}
}
private async void ThemeChanged()
{
//TODO: Update user settings
StateHasChanged();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && _themeProvider != null)
{
DarkTheme = await _themeProvider.GetSystemPreference();
_themeProvider.IsDarkModeChanged = EventCallback.Factory.Create(this, x => OnDarkThemeChanged?.Invoke(this, x));
}
}
}