Fixed exception
This commit is contained in:
Родитель
6d4d290acb
Коммит
48c779b2bf
|
@ -112,7 +112,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications
|
|||
/// <returns>The current instance of <see cref="ToastContentBuilder"/></returns>
|
||||
public ToastContentBuilder AddButton(IToastButton button)
|
||||
{
|
||||
if (button is ToastButton toastButton && toastButton.Content == null)
|
||||
if (button is ToastButton toastButton && toastButton.Content == null && toastButton.NeedsContent())
|
||||
{
|
||||
throw new InvalidOperationException("Content is required on button.");
|
||||
}
|
||||
|
|
|
@ -25,6 +25,12 @@ namespace Microsoft.Toolkit.Uwp.Notifications
|
|||
|
||||
private bool _usingDismissActivation;
|
||||
|
||||
internal bool NeedsContent()
|
||||
{
|
||||
// Snooze/dismiss buttons don't need content (the system will auto-add the localized strings).
|
||||
return !_usingDismissActivation && !_usingSnoozeActivation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ToastButton"/> class.
|
||||
/// </summary>
|
||||
|
@ -428,11 +434,23 @@ namespace Microsoft.Toolkit.Uwp.Notifications
|
|||
{
|
||||
el.InputId = _snoozeSelectionBoxId;
|
||||
}
|
||||
|
||||
// Content needs to be specified as empty for auto-generated Snooze content
|
||||
if (el.Content == null)
|
||||
{
|
||||
el.Content = string.Empty;
|
||||
}
|
||||
}
|
||||
else if (_usingDismissActivation)
|
||||
{
|
||||
el.ActivationType = Element_ToastActivationType.System;
|
||||
el.Arguments = "dismiss";
|
||||
|
||||
// Content needs to be specified as empty for auto-generated Dismiss content
|
||||
if (el.Content == null)
|
||||
{
|
||||
el.Content = string.Empty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -980,7 +980,7 @@ namespace UnitTests.Notifications
|
|||
[TestMethod]
|
||||
public void Test_Toast_Xml_Actions_SnoozeAndDismissUsingBuilders()
|
||||
{
|
||||
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()
|
||||
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()
|
||||
{
|
||||
Buttons =
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче