Table of Contents

Class SnackbarService

Namespace
MudBlazor
Assembly
MudBlazor.dll

A service for managing snackbars.

public class SnackbarService : ISnackbar, IDisposable
Inheritance
SnackbarService
Implements
Inherited Members
Extension Methods

Constructors

SnackbarService(NavigationManager, IOptions<SnackbarConfiguration>?)

public SnackbarService(NavigationManager navigationManager, IOptions<SnackbarConfiguration>? configuration = null)

Parameters

navigationManager NavigationManager
configuration IOptions<SnackbarConfiguration>

Properties

Configuration

The global configuration for each snackbar.

public SnackbarConfiguration Configuration { get; }

Property Value

SnackbarConfiguration

ShownSnackbars

The collection of currently shown snackbars.

public IEnumerable<Snackbar> ShownSnackbars { get; }

Property Value

IEnumerable<Snackbar>

Methods

Add(MarkupString, Severity, Action<SnackbarOptions>?, string?)

Adds a new snackbar with the specified markup message.

public Snackbar? Add(MarkupString message, Severity severity = Severity.Normal, Action<SnackbarOptions>? configure = null, string? key = null)

Parameters

message MarkupString

The markup message to display in the snackbar.

severity Severity

The severity of the snackbar message. Default is Normal.

configure Action<SnackbarOptions>

Optional action to configure the SnackbarOptions.

key string

An optional key to uniquely identify the snackbar. Default is the value of message.

Returns

Snackbar

The created snackbar instance, or null if not created.

Remarks

If a key is provided, this snackbar will not be shown while any snackbar with the same key is being shown.

Add(RenderFragment, Severity, Action<SnackbarOptions>?, string?)

Adds a new snackbar with the specified render fragment.

public Snackbar? Add(RenderFragment message, Severity severity = Severity.Normal, Action<SnackbarOptions>? configure = null, string? key = null)

Parameters

message RenderFragment

The render fragment to display in the snackbar.

severity Severity

The severity of the snackbar message. Default is Normal.

configure Action<SnackbarOptions>

Optional action to configure the SnackbarOptions.

key string

An optional key to uniquely identify the snackbar.

Returns

Snackbar

The created snackbar instance, or null if not created.

Remarks

If a key is provided, this snackbar will not be shown while any snackbar with the same key is being shown.

Add(string, Severity, Action<SnackbarOptions>?, string?)

Adds a new snackbar with the specified message.

public Snackbar? Add(string message, Severity severity = Severity.Normal, Action<SnackbarOptions>? configure = null, string? key = null)

Parameters

message string

The message to display in the snackbar.

severity Severity

The severity of the snackbar message. Defaults to Normal.

configure Action<SnackbarOptions>

Optional action to configure the SnackbarOptions.

key string

An optional key to uniquely identify the snackbar. Default is the value of message.

Returns

Snackbar

The created snackbar instance, or null if not created.

Remarks

If a key is provided, this snackbar will not be shown while any snackbar with the same key is being shown.

Add<T>(Dictionary<string, object>?, Severity, Action<SnackbarOptions>?, string?)

Adds a new snackbar with the specified component.

public Snackbar? Add<T>(Dictionary<string, object>? componentParameters = null, Severity severity = Severity.Normal, Action<SnackbarOptions>? configure = null, string? key = null) where T : IComponent

Parameters

componentParameters Dictionary<string, object>

Optional parameters to pass to the component.

severity Severity

The severity of the snackbar message. Default is Normal.

configure Action<SnackbarOptions>

Optional action to configure the SnackbarOptions.

key string

An optional key to uniquely identify the snackbar.

Returns

Snackbar

The created snackbar instance, or null if not created.

Type Parameters

T

The component type to render inside the snackbar.

Remarks

If a key is provided, this snackbar will not be shown while any snackbar with the same key is being shown.

Clear()

Clears all displayed snackbars.

public void Clear()

Dispose()

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Remove(Snackbar)

Removes the specified snackbar.

public void Remove(Snackbar snackbar)

Parameters

snackbar Snackbar

The snackbar to remove.

RemoveByKey(string)

Removes a snackbar by its key.

public void RemoveByKey(string key)

Parameters

key string

The key of the snackbar to remove.

Events

OnSnackbarsUpdated

Event triggered when the collection of shown snackbars is updated.

public event Action? OnSnackbarsUpdated

Event Type

Action