|
| 1 | +--- |
| 2 | +description: Learn how to organize app notifications by creating, updating, or removing notification collections in Notification Center. |
| 3 | +title: App notification collections |
| 4 | +label: App notification collections |
| 5 | +template: detail.hbs |
| 6 | +ms.date: 07/28/2025 |
| 7 | +ms.topic: how-to |
| 8 | +keywords: windows 11, windows app sdk, winappsdk, notification, collections, collection, group notifications, grouping notifications, group, organize, Notification Center |
| 9 | +ms.localizationpriority: medium |
| 10 | +--- |
| 11 | +# App notification collections |
| 12 | + |
| 13 | +Use collections to organize your app's notifications in Notification Center. Collections help users locate information more easily and allow developers to better manage their notifications. |
| 14 | + |
| 15 | +A messaging app, for example, can separate notifications by chat group. Each group title ("Comp Sci 160A Project Chat", "Direct Messages", "Lacrosse Team Chat") is a separate collection. Notifications are grouped as if they were from a separate app, even though they all come from the same app. For a more subtle way to organize notifications, see [App notification headers](toast-headers.md). |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +> [!NOTE] |
| 20 | +> The code examples in this article use the `Microsoft.Windows.AppNotifications` namespace to build notification content and the `Windows.UI.Notifications` namespace for collection management. These two namespaces can be used together in the same app. |
| 21 | +
|
| 22 | +For more information about app notifications, see [App notifications overview](index.md). |
| 23 | + |
| 24 | +## Create a collection |
| 25 | + |
| 26 | +When creating a collection, provide a display name and an icon, which are shown in Notification Center as part of the collection's title. Collections also require a launch argument so your app can navigate to the right location when the user clicks the collection title. Create the collection by calling [**SaveToastCollectionAsync**](/uwp/api/windows.ui.notifications.toastcollectionmanager.savetoastcollectionasync). |
| 27 | + |
| 28 | +```csharp |
| 29 | +using Windows.UI.Notifications; |
| 30 | + |
| 31 | +var collection = new ToastCollection( |
| 32 | + "MyToastCollection", |
| 33 | + "Work Email", |
| 34 | + "NavigateToWorkEmailInbox", |
| 35 | + new Uri("ms-appx:///Assets/workEmail.png")); |
| 36 | + |
| 37 | +await ToastNotificationManager.GetDefault() |
| 38 | + .GetToastCollectionManager() |
| 39 | + .SaveToastCollectionAsync(collection); |
| 40 | +``` |
| 41 | + |
| 42 | +## Send a notification to a collection |
| 43 | + |
| 44 | +Use [**AppNotificationBuilder**](/windows/windows-app-sdk/api/winrt/microsoft.windows.appnotifications.builder.appnotificationbuilder) to construct the notification content, then call [**GetToastNotifierForToastCollectionIdAsync**](/uwp/api/windows.ui.notifications.toastnotificationmanagerforuser.gettoastnotifierfortoastcollectionidasync) to get a notifier scoped to the collection. |
| 45 | + |
| 46 | +```csharp |
| 47 | +using Microsoft.Windows.AppNotifications.Builder; |
| 48 | +using Windows.UI.Notifications; |
| 49 | +using Windows.Data.Xml.Dom; |
| 50 | + |
| 51 | +// Build notification content with Windows App SDK |
| 52 | +var payload = new AppNotificationBuilder() |
| 53 | + .AddText("Adam sent a message to the group") |
| 54 | + .BuildNotification() |
| 55 | + .Payload; |
| 56 | + |
| 57 | +// Deliver to a collection using the WinRT API |
| 58 | +var doc = new XmlDocument(); |
| 59 | +doc.LoadXml(payload); |
| 60 | +var toast = new ToastNotification(doc); |
| 61 | + |
| 62 | +var notifier = await ToastNotificationManager.GetDefault() |
| 63 | + .GetToastNotifierForToastCollectionIdAsync("MyToastCollection"); |
| 64 | +notifier.Show(toast); |
| 65 | +``` |
| 66 | + |
| 67 | +## List all collections |
| 68 | + |
| 69 | +Retrieve all collections created for your app by calling [**FindAllToastCollectionsAsync**](/uwp/api/windows.ui.notifications.toastcollectionmanager.findalltoastcollectionsasync). |
| 70 | + |
| 71 | +```csharp |
| 72 | +var collectionManager = ToastNotificationManager.GetDefault().GetToastCollectionManager(); |
| 73 | +var collections = await collectionManager.FindAllToastCollectionsAsync(); |
| 74 | +``` |
| 75 | + |
| 76 | +## Update a collection |
| 77 | + |
| 78 | +Update a collection by creating a new [**ToastCollection**](/uwp/api/windows.ui.notifications.toastcollection) instance with the same ID and calling [**SaveToastCollectionAsync**](/uwp/api/windows.ui.notifications.toastcollectionmanager.savetoastcollectionasync). |
| 79 | + |
| 80 | +```csharp |
| 81 | +var collectionManager = ToastNotificationManager.GetDefault().GetToastCollectionManager(); |
| 82 | + |
| 83 | +var updatedCollection = new ToastCollection( |
| 84 | + "MyToastCollection", |
| 85 | + "Updated Display Name", |
| 86 | + "UpdatedLaunchArgs", |
| 87 | + new Uri("ms-appx:///Assets/updatedPicture.png")); |
| 88 | + |
| 89 | +await collectionManager.SaveToastCollectionAsync(updatedCollection); |
| 90 | +``` |
| 91 | + |
| 92 | +## Remove a collection |
| 93 | + |
| 94 | +Remove a collection by calling [**RemoveToastCollectionAsync**](/uwp/api/windows.ui.notifications.toastcollectionmanager.removetoastcollectionasync) with the collection ID. Any notifications in the collection are also removed from Notification Center. |
| 95 | + |
| 96 | +```csharp |
| 97 | +var collectionManager = ToastNotificationManager.GetDefault().GetToastCollectionManager(); |
| 98 | +await collectionManager.RemoveToastCollectionAsync("MyToastCollection"); |
| 99 | +``` |
| 100 | + |
| 101 | +## Remove notifications within a collection |
| 102 | + |
| 103 | +Use the **Tag** and **Group** properties to identify and remove individual notifications within a collection by calling [**Remove**](/uwp/api/windows.ui.notifications.toastnotificationhistory.remove), or clear all notifications at once with [**Clear**](/uwp/api/windows.ui.notifications.toastnotificationhistory.clear). |
| 104 | + |
| 105 | +```csharp |
| 106 | +var collectionHistory = await ToastNotificationManager.GetDefault() |
| 107 | + .GetHistoryForToastCollectionAsync("MyToastCollection"); |
| 108 | + |
| 109 | +// Remove a specific notification |
| 110 | +collectionHistory.Remove(tag, group); |
| 111 | + |
| 112 | +// Or clear all notifications in the collection |
| 113 | +collectionHistory.Clear(); |
| 114 | +``` |
| 115 | + |
| 116 | +## See also |
| 117 | + |
| 118 | +- [App notifications overview](index.md) |
0 commit comments