我想做一个定期的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);
}
}
错误在哪里?
提前致谢!
答案 0 :(得分:1)
snoozeInterval
构造函数的参数ScheduledToastNotification
的值应介于1分钟到1小时之间。
因此,只需将您获得异常的代码行更改为以下内容:
ScheduledToastNotification toast = new ScheduledToastNotification(xml, offset, TimeSpan.FromMinutes(1), 5);