Overview
This sample demonstrates how to receive and display push notifications in a Windows desktop application built with the Windows App SDK.
Prerequisites
- Windows 10 version 1809 or later
- Windows App SDK 1.4 or newer
- Microsoft Edge WebView2 Runtime
- Azure Notification Hubs (or any WNS compatible service)
Setup
Add the Microsoft.WindowsAppSDK
NuGet package to your project and configure the AppManifest
with the proper package identity.
Code Sample
// Register for push notifications
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
Console.WriteLine($"Channel URI: {channel.Uri}");
// Listen for incoming notifications
channel.PushNotificationReceived += (sender, args) =>
{
// Show toast UI
var content = args.ToastNotification.Content.GetXml();
var toast = new Windows.UI.Notifications.ToastNotification(new Windows.Data.Xml.Dom.XmlDocument{ LoadXml(content) });
Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().Show(toast);
args.Cancel = true; // Prevent default handling
};
Test Push Notification
Click the button below to simulate receiving a push notification.