Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.22 KB

File metadata and controls

56 lines (38 loc) · 1.22 KB

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