Interface IMBSnackbarService
Interface for the Material.Blazor snackbar service, developed from the code base of Blazored Snackbar by Chris Sainty. Works in conjunction with a MBAnchor that must be placed in either App.razor or MainLayout.razor to avoid an exception being thrown when you first attempt to show a snackbar notification.
Throws a InvalidOperationException if ShowSnackbar(string, Action, string, string, MBNotifierCloseMethod?, bool, bool, int?, bool) is called without an MBAnchor component used in the app.
You can optionally add configuration when you add this to the service collection:
services.AddMBServices(snackbarServiceConfiguration: new MBSnackbarServiceConfiguration()
{
Timeout = 4000,
CloseMethod = MBSnackbarCloseMethod.Timeout,
... etc
});
public interface IMBSnackbarService
Properties
Configuration
Snackbar service configuration
MBSnackbarServiceConfiguration Configuration { get; set; }
Property Value
Methods
ShowSnackbar(string, Action, string, string, MBNotifierCloseMethod?, bool, bool, int?, bool)
Shows a snackbar using the supplied settings. Only the level and message parameters are required, with the remainder haveing defaults specified by the MBSnackbarServiceConfiguration that you can supply when registering services. Failing that Material.Blazor provides defaults.
void ShowSnackbar(string message, Action action = null, string actionText = null, string additionalClass = null, MBNotifierCloseMethod? closeMethod = null, bool leading = false, bool stacked = false, int? timeout = null, bool debug = false)
Parameters
message
stringBody text in the snackbar
action
ActionThe action that is performed when the button in the snackbar is clicked (optional. if set, 'actionText' must also be set)
actionText
stringThe text to display in the action button in the snackbar (optional. if set, 'action' must also be set)
additionalClass
stringThe name of a class to be added to the snackbar surface
closeMethod
MBNotifierCloseMethod?Snackbars are intended to dismiss on their own after a few seconds, but a dedicated dismiss icon may be optionally included as well for accessibility purposes
leading
boolBy default, snackbars are centered horizontally within the viewport. On larger screens, they can optionally be displayed on the leading edge of the screen (the left side in LTR, or the right side in RTL)
stacked
boolAction buttons with long text should be positioned below the label instead of alongside it
timeout
int?Length of time before autodismiss
debug
boolIf true only shows snackbars when compiling in DEBUG mode
Events
OnAdd
A event that will be invoked when showing a snackbar
event Action<MBSnackbarSettings> OnAdd
Event Type
OnTriggerStateHasChanged
A event that will be invoked when snackbars should call StateHasChanged. This will be when the configuration is updated.
event Action OnTriggerStateHasChanged