Skip to content

Commit 48c779b

Browse files
committed
Fixed exception
1 parent 6d4d290 commit 48c779b

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.Actions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public ToastContentBuilder AddButton(string content, ToastActivationType activat
112112
/// <returns>The current instance of <see cref="ToastContentBuilder"/></returns>
113113
public ToastContentBuilder AddButton(IToastButton button)
114114
{
115-
if (button is ToastButton toastButton && toastButton.Content == null)
115+
if (button is ToastButton toastButton && toastButton.Content == null && toastButton.NeedsContent())
116116
{
117117
throw new InvalidOperationException("Content is required on button.");
118118
}

Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastButton.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public sealed class ToastButton :
2525

2626
private bool _usingDismissActivation;
2727

28+
internal bool NeedsContent()
29+
{
30+
// Snooze/dismiss buttons don't need content (the system will auto-add the localized strings).
31+
return !_usingDismissActivation && !_usingSnoozeActivation;
32+
}
33+
2834
/// <summary>
2935
/// Initializes a new instance of the <see cref="ToastButton"/> class.
3036
/// </summary>
@@ -428,11 +434,23 @@ internal Element_ToastAction ConvertToElement()
428434
{
429435
el.InputId = _snoozeSelectionBoxId;
430436
}
437+
438+
// Content needs to be specified as empty for auto-generated Snooze content
439+
if (el.Content == null)
440+
{
441+
el.Content = string.Empty;
442+
}
431443
}
432444
else if (_usingDismissActivation)
433445
{
434446
el.ActivationType = Element_ToastActivationType.System;
435447
el.Arguments = "dismiss";
448+
449+
// Content needs to be specified as empty for auto-generated Dismiss content
450+
if (el.Content == null)
451+
{
452+
el.Content = string.Empty;
453+
}
436454
}
437455
else
438456
{

UnitTests/UnitTests.Notifications.Shared/Test_Toast_Xml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ public void Test_Toast_Xml_Actions_SixTotal()
980980
[TestMethod]
981981
public void Test_Toast_Xml_Actions_SnoozeAndDismissUsingBuilders()
982982
{
983-
AssertActionsPayload("<actions><action activationType='system' arguments='snooze'/><action activationType='system' arguments='dismiss'/><action content='Hide' activationType='system' arguments='dismiss'/><action content='Later' activationType='system' arguments='snooze'/><action content='Remind me' activationType='system' arguments='snooze' hint-inputId='snoozePicker'/></actions>", new ToastActionsCustom()
983+
AssertActionsPayload("<actions><action content='' activationType='system' arguments='snooze'/><action content='' activationType='system' arguments='dismiss'/><action content='Hide' activationType='system' arguments='dismiss'/><action content='Later' activationType='system' arguments='snooze'/><action content='Remind me' activationType='system' arguments='snooze' hint-inputId='snoozePicker'/></actions>", new ToastActionsCustom()
984984
{
985985
Buttons =
986986
{

0 commit comments

Comments
 (0)