Primary APIs:
INotificationNotificationINotificationManagerIManagedNotificationManagerWindowNotificationManagerNotificationTypeNotificationPositionNotificationCardImportant members:
WindowNotificationManager.Position, MaxItemsWindowNotificationManager.Show(INotification)WindowNotificationManager.Show(object)WindowNotificationManager.Show(object, NotificationType, TimeSpan?, Action?, Action?, string[]?)WindowNotificationManager.Close(INotification), Close(object), CloseAll()Notification.Title, Message, Type, Expiration, OnClick, OnCloseReference source files:
src/Avalonia.Controls/Notifications/INotification.cssrc/Avalonia.Controls/Notifications/INotificationManager.cssrc/Avalonia.Controls/Notifications/IManagedNotificationManager.cssrc/Avalonia.Controls/Notifications/Notification.cssrc/Avalonia.Controls/Notifications/NotificationType.cssrc/Avalonia.Controls/Notifications/NotificationPosition.cssrc/Avalonia.Controls/Notifications/WindowNotificationManager.cssrc/Avalonia.Controls/Notifications/NotificationCard.csNotification is the default managed model implementing INotification.
Core semantics:
Type controls visual severity (Information, Success, Warning, Error).Expiration controls auto-close timeout.Expiration == TimeSpan.Zero means stay open until closed.OnClick and OnClose provide optional callbacks.using System;
using Avalonia.Controls.Notifications;
var notification = new Notification(
title: "Sync complete",
message: "42 files uploaded.",
type: NotificationType.Success,
expiration: TimeSpan.FromSeconds(4),
onClick: () => OpenSyncLog(),
onClose: () => MarkToastSeen());
This is the common app pattern: create WindowNotificationManager bound to current TopLevel.
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
public partial class DashboardView : UserControl
{
private WindowNotificationManager? _notifications;
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is not null)
{
_notifications = new WindowNotificationManager(topLevel)
{
Position = NotificationPosition.BottomRight,
MaxItems = 4
};
}
}
private void NotifySaved()
{
_notifications?.Show(new Notification("Saved", "Preferences updated.", NotificationType.Success));
}
}
Implementation detail:
AdornerLayer of host top-level.For local notification regions, declare a manager in view XAML and call it via command/event wiring.
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:NotificationsViewModel">
<DockPanel>
<Button DockPanel.Dock="Top"
Content="Show Info"
Command="{Binding #LocalNotifications.Show}">
<Button.CommandParameter>
<Notification Title="Info" Message="Local notification example." Type="Information" />
</Button.CommandParameter>
</Button>
<Border Padding="12">
<WindowNotificationManager x:Name="LocalNotifications"
Position="TopRight"
MaxItems="3" />
</Border>
</DockPanel>
</UserControl>
Show arbitrary content:
using Avalonia.Controls.Notifications;
WindowNotificationManager manager = new();
manager.Show("Simple message");
Show custom content with classes and callbacks:
using System;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
manager.Show(
content: new TextBlock { Text = "Deployment started." },
type: NotificationType.Information,
expiration: TimeSpan.FromSeconds(6),
onClick: () => OpenDeployPage(),
onClose: () => LogClosed(),
classes: new[] { "deployment", "sticky" });
Close specific or all notifications:
var n = new Notification("Warning", "Connection unstable.", NotificationType.Warning, TimeSpan.Zero);
manager.Show(n);
manager.Close(n);
manager.CloseAll();
WindowNotificationManager.Position controls pseudo classes:
:topleft:topright:bottomleft:bottomright:topcenter:bottomcenterNotificationCard provides type pseudo classes:
:information:success:warning:errorUse these in custom styles/themes to align visuals with app branding.
MaxItems conservative to avoid notification overload.TimeSpan.Zero only for truly actionable notifications.Notification objects for user-facing toasts.TopLevel or present in visual tree.Expiration or set TimeSpan.Zero for sticky notifications.MaxItems.Close(notification) does not find card.