Primary WinForms APIs:
NotifyIcon.ShowBalloonTip(...)MessageBox.Show(...)TaskDialog patternsPrimary Avalonia APIs/patterns:
TrayIcon for system-tray presenceWindowNotificationManager + Notification for in-app toasts| WinForms | Avalonia |
|---|---|
| tray balloon tip | tray integration + in-app toast notifications |
MessageBox.Show blocking dialog |
async Window.ShowDialog(owner) flow |
| task-oriented dialogs | custom dialog views with explicit commands |
WinForms C#:
notifyIcon.ShowBalloonTip(3000, "Saved", "Customer updated.", ToolTipIcon.Info);
if (MessageBox.Show("Delete record?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Delete();
}
Avalonia XAML:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:NotificationsViewModel">
<StackPanel Spacing="8">
<Button Content="Show Success Toast"
Command="{CompiledBinding ShowSuccessCommand}" />
<Button Content="Confirm Delete"
Command="{CompiledBinding ConfirmDeleteCommand}" />
</StackPanel>
</UserControl>
using System;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using Avalonia.Layout;
public static class NotificationFlows
{
public static void ShowSavedToast(Window owner)
{
var manager = new WindowNotificationManager(owner)
{
Position = NotificationPosition.TopRight,
MaxItems = 3
};
manager.Show(new Notification(
"Saved",
"Customer updated.",
NotificationType.Success,
TimeSpan.FromSeconds(3)));
}
public static async Task<bool> ConfirmDeleteAsync(Window owner)
{
var dialog = new Window
{
Width = 360,
Height = 180,
CanResize = false,
Title = "Confirm Delete",
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
var confirm = new Button { Content = "Delete" };
var cancel = new Button { Content = "Cancel" };
confirm.Click += (_, _) => dialog.Close(true);
cancel.Click += (_, _) => dialog.Close(false);
dialog.Content = new StackPanel
{
Margin = new Thickness(12),
Spacing = 10,
Children =
{
new TextBlock { Text = "Delete selected record?" },
new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
Spacing = 8,
Children = { cancel, confirm }
}
}
};
return await dialog.ShowDialog<bool>(owner);
}
}
Window/TopLevel.