Windows App SDK – Sample Push Notifications

Overview

This sample demonstrates how to receive and display push notifications in a Windows desktop application built with the Windows App SDK.

Prerequisites

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.