Skip to content

mortenbrudvik/WPFWindowToastNotification

Repository files navigation

A simple example of testing and showing Windows toast notifications.

snapshot

Toast notification

notification

How all this is done

Install nuget package

Microsoft.Toolkit.Uwp.Notifications

Specify window version in project file to enable Windows notifications

<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>

Create and show a toast message

var toastBuilder = new ToastContentBuilder()  
	.AddArgument("action", "general")  
	.AddArgument("actionId", 344)  
	.AddText("You got a mail!")  
	.AddText("You won the lottery!");  
      
toastBuilder.Show();

Handle toast actions

ToastNotificationManagerCompat.OnActivated += toastArgs =>  
{  
	ToastArguments args = ToastArguments.Parse(toastArgs.Argument);  

	Application.Current.Dispatcher.Invoke(delegate  
	{  
		 MessageBox.Show("Toast activated. Args: " + args);  
	});  
};  

Cleaning up messages

ToastNotificationManagerCompat.Uninstall();

For more info about the Toast API, check out: Toast UX Guidance - Windows apps | Microsoft Docs

About

Windows Toast Notification Demo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages