繁体   English   中英

预定吐司通知UWP

[英]Scheduled Toast Notification UWP

我想定期进行一次敬酒通知。

编码:

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);
    }
}

脚本发生错误:参数错误。 在此处输入图片说明

错误在哪里?

提前致谢!

ScheduledToastNotification构造函数的参数snoozeInterval的值范围应在1分钟到1小时之间。

因此,只需将获得异常的代码行更改为如下所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM