Toast
Sonner-style notifications that stack in a corner and dismiss themselves.
Call Toast.Show (or Success, Error, Warning, Info) from anywhere. Toasts float above the page, pause while hovered, and go after four seconds.
Installation
bash
shellui-native add toast
Platforms: MAUI · Avalonia. Also installs icon, button, button-variants.
Usage
Basic
<ui:Button Text="Show toast" Variant="Outline" Clicked="OnShow" />
<ui:Button Text="Success" Variant="Outline" Clicked="OnSuccess" />
<ui:Button Text="Error" Variant="Outline" Clicked="OnError" />
<ui:Button Text="Warning" Variant="Outline" Clicked="OnWarning" /><ui:Button Text="Show toast" Variant="Outline" Clicked="OnShow" />
<ui:Button Text="Success" Variant="Outline" Clicked="OnSuccess" />
<ui:Button Text="Error" Variant="Outline" Clicked="OnError" />
<ui:Button Text="Warning" Variant="Outline" Clicked="OnWarning" />Not available on yet
csharp
private void OnShow(object? sender, EventArgs e) =>
Toast.Show("Event has been created", "Sunday, December 03 at 9:00 AM");
private void OnSuccess(object? sender, EventArgs e) => Toast.Success("Profile saved");
private void OnError(object? sender, EventArgs e) =>
Toast.Error("Upload failed", "The file is larger than 10 MB.");
private void OnWarning(object? sender, EventArgs e) =>
Toast.Warning("Storage almost full", "92% of your quota used.");
Action
A toast can carry one action button. Pressing it runs the action and dismisses the toast:
csharp
Toast.Show("Message archived", actionText: "Undo", action: Unarchive);
Position
Without a Toaster, toasts stack in the bottom-right corner, three at a time. Declare one anywhere to change that:
xml
<ui:Toaster Position="TopRight" MaxVisible="5" />
MAUI and Avalonia
On MAUI the Toaster goes on a page; on Avalonia in a window. Without one, Toast.Show uses the page (MAUI) or window (Avalonia) on screen.
API
Toast
| Method | Description |
|---|---|
Toast.Show(string message, string? description = null, ToastVariant variant = ToastVariant.Default, TimeSpan? duration = null, string? actionText = null, Action? action = null) |
Shows a toast and returns its id. |
Toast.Success(string message, string? description = null, TimeSpan? duration = null, string? actionText = null, Action? action = null) |
Shows a success toast and returns its id. |
Toast.Error(string message, string? description = null, TimeSpan? duration = null, string? actionText = null, Action? action = null) |
Shows an error toast and returns its id. |
Toast.Warning(string message, string? description = null, TimeSpan? duration = null, string? actionText = null, Action? action = null) |
Shows a warning toast and returns its id. |
Toast.Info(string message, string? description = null, TimeSpan? duration = null, string? actionText = null, Action? action = null) |
Shows an info toast and returns its id. |
Toast.Dismiss(string id) |
Dismisses the toast with this id. |
Toaster
| Property | Type | Default | Description |
|---|---|---|---|
Position |
ToasterPosition |
BottomRight |
Corner (or edge) the toasts stack in. One of BottomRight, BottomCenter, TopRight, TopCenter. |
MaxVisible |
int |
3 |
Most toasts shown at once; older ones are dismissed. |