簡體   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