Skip to content

Commit 8f37124

Browse files
drewbatgitCopilot
andcommitted
Fix toast-headers and toast-collections code snippets
- toast-headers.md: Replace non-existent SetHeader/AppNotificationHeader with raw XML via AppNotification constructor; add note about API gap - toast-collections.md: Parse Payload string into XmlDocument before passing to ToastNotification constructor Co-authored-by: Copilot <[email protected]>
1 parent e188682 commit 8f37124

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

hub/apps/develop/notifications/app-notifications/toast-collections.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ var notification = new AppNotificationBuilder()
9696
.BuildNotification();
9797

9898
// For collection-based delivery, use the WinRT ToastNotification with the XML payload
99-
var toast = new ToastNotification(notification.Payload);
99+
var xmlDoc = new Windows.Data.Xml.Dom.XmlDocument();
100+
xmlDoc.LoadXml(notification.Payload);
101+
var toast = new ToastNotification(xmlDoc);
100102

101103
// Get the collection notifier
102104
var notifier = await ToastNotificationManager.GetDefault().GetToastNotifierForToastCollectionIdAsync("MyToastCollection");

hub/apps/develop/notifications/app-notifications/toast-headers.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@ Here's how you add a header to an app notification.
3030
3131
#### [Windows App SDK](#tab/appsdk)
3232

33+
> [!NOTE]
34+
> `AppNotificationBuilder` doesn't currently include a `SetHeader` method, so use the XML payload directly with the `AppNotification` constructor.
35+
3336
```csharp
34-
new AppNotificationBuilder()
35-
.SetHeader(new AppNotificationHeader("6289", "Camping!!", "action=openConversation&id=6289"))
36-
.AddText("Anyone have a sleeping bag I can borrow?");
37+
string xml = @"
38+
<toast>
39+
<header id='6289' title='Camping!!' arguments='action=openConversation&amp;id=6289'/>
40+
<visual>
41+
<binding template='ToastGeneric'>
42+
<text>Anyone have a sleeping bag I can borrow?</text>
43+
</binding>
44+
</visual>
45+
</toast>";
46+
47+
var notification = new AppNotification(xml);
48+
AppNotificationManager.Default.Show(notification);
3749
```
3850

3951
#### [Community Toolkit](#tab/toolkit)

0 commit comments

Comments
 (0)