Table of Contents

Class MudThemeProvider

Namespace
MudBlazor
Assembly
MudBlazor.dll

Provides a standard set of colors, shapes, sizes and shadows to a layout.

public class MudThemeProvider : ComponentBaseWithState, IComponent, IHandleEvent, IHandleAfterRender, IDisposable
Inheritance
MudThemeProvider
Implements
Inherited Members
Extension Methods

Constructors

MudThemeProvider()

public MudThemeProvider()

Properties

DefaultScrollbar

Uses the browser default scrollbar instead of the MudBlazor scrollbar.

[Parameter]
public bool DefaultScrollbar { get; set; }

Property Value

bool

Remarks

Defaults to false.

IsDarkMode

Uses darker colors for all MudBlazor components.

[Parameter]
public bool IsDarkMode { get; set; }

Property Value

bool

Remarks

Defaults to false. When this value changes, IsDarkModeChanged occurs.

When true, the PaletteDark colors will be used.

When false, the PaletteLight colors will be used.

IsDarkModeChanged

Occurs when IsDarkMode has changed.

[Parameter]
public EventCallback<bool> IsDarkModeChanged { get; set; }

Property Value

EventCallback<bool>

ObserveSystemThemeChange

Detects when the system theme has changed between Light Mode and Dark Mode.

[Parameter]
public bool ObserveSystemThemeChange { get; set; }

Property Value

bool

Remarks

Defaults to true.
When true, the theme will automatically change to Light Mode or Dark Mode as the system theme changes.

Theme

The theme used by the application.

[Parameter]
public MudTheme? Theme { get; set; }

Property Value

MudTheme

Methods

BuildMudBlazorScrollbar()

Gets the CSS styles for the browser scrollbar.

protected static string BuildMudBlazorScrollbar()

Returns

string

A style HTML element containing the scrollbar's styles.

BuildRenderTree(RenderTreeBuilder)

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

BuildTheme()

Gets the CSS styles for this provider.

protected string BuildTheme()

Returns

string

A style HTML element containing this theme's styles.

Dispose()

Releases resources used by this component.

public void Dispose()

GenerateTheme(StringBuilder)

Generates the CSS styles for the specified theme.

protected virtual void GenerateTheme(StringBuilder theme)

Parameters

theme StringBuilder

The theme to append to.

Remarks

Several CSS values for color, opacity, and elevation are appended based on the value of IsDarkMode.

GetSystemPreference()

Gets whether the system is using Dark Mode.

public Task<bool> GetSystemPreference()

Returns

Task<bool>

When true, the system is using Dark Mode.
When false, the system is using Light Mode.

OnAfterRenderAsync(bool)

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Returns

Task

OnInitialized()

protected override void OnInitialized()

OnParametersSet()

protected override void OnParametersSet()

SystemPreferenceChanged(bool)

Occurs when the system theme has changed.

[JSInvokable]
public Task SystemPreferenceChanged(bool isDarkMode)

Parameters

isDarkMode bool

When true, the system is in Dark Mode.

Returns

Task

WatchSystemPreference(Func<bool, Task>)

Calls a function when the system theme has changed.

public Task WatchSystemPreference(Func<bool, Task> functionOnChange)

Parameters

functionOnChange Func<bool, Task>

The function to call when the system theme has changed.

Returns

Task

Remarks

A value of true is passed if the system is now in Dark Mode. Otherwise, the system is now in Light Mode.

See Also