预定的Toast通知UWP

时间:2017-11-24 20:07:44

标签: c# notifications uwp

我想做一个定期的toastnotification。

代码:

public sealed partial class MainPage : Page
{
    const string TOAST = @"
                        <toast>
                          <visual>
                            <binding template=""ToastTest"">
                              <text>Hello Toast</text>
                            </binding>
                          </visual>
                          <audio src =""ms-winsoundevent:Notification.Mail"" loop=""true""/>
                        </toast>";

    public MainPage()
    {
        this.InitializeComponent();
    }

    private void btnNotification_Click(object sender, RoutedEventArgs e)
    {
        var when = DateTime.Now.AddSeconds(6);
        var offset = new DateTimeOffset(when);

        Windows.Data.Xml.Dom.XmlDocument xml = new Windows.Data.Xml.Dom.XmlDocument();
        xml.LoadXml(TOAST);
        ScheduledToastNotification toast = new ScheduledToastNotification(xml, offset, TimeSpan.FromSeconds(5), 5);
        toast.Id = "IdTostone";
        toast.Tag = "NotificationOne";
        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
    }
}

脚本出错:参数不正确。 enter image description here

错误在哪里?

提前致谢!

1 个答案:

答案 0 :(得分:1)

snoozeInterval构造函数的参数ScheduledToastNotification的值应介于1分钟到1小时之间。

因此,只需将您获得异常的代码行更改为以下内容:

ScheduledToastNotification toast = new ScheduledToastNotification(xml, offset, TimeSpan.FromMinutes(1), 5);