Share via


ScheduledToastNotification 建構函式

定義

多載

ScheduledToastNotification(XmlDocument, DateTime)

建立並初始化 ScheduledToastNotification 的新實例,該實例只會顯示一次。

ScheduledToastNotification(XmlDocument, DateTime, TimeSpan, UInt32)

Windows 10中已被取代。 在 Windows 8 系統上,建立並初始化 ScheduledToastNotification 的新實例,該實例會在一開始出現之後的指定時間之後重新出現。 在Windows 10上,此函式相當於ScheduledToastNotification (XmlDocument、DateTime) 。 若要在Windows 10中達到相同的延遲間隔行為,您可以在快顯通知上使用按鈕

ScheduledToastNotification(XmlDocument, DateTime)

建立並初始化 ScheduledToastNotification 的新實例,該實例只會顯示一次。

public:
 ScheduledToastNotification(XmlDocument ^ content, DateTime deliveryTime);
 ScheduledToastNotification(XmlDocument const& content, DateTime const& deliveryTime);
public ScheduledToastNotification(XmlDocument content, System.DateTimeOffset deliveryTime);
function ScheduledToastNotification(content, deliveryTime)
Public Sub New (content As XmlDocument, deliveryTime As DateTimeOffset)

參數

content
XmlDocument

定義快顯通知內容的 XML。

deliveryTime
DateTime DateTimeOffset

Windows 應該顯示快顯通知的日期和時間。 您必須在此時間之前呼叫 AddToSchedule

範例

下列範例顯示排定在一小時內顯示的快顯通知,包括使用此建構函式來建立通知。

var Notifications = Windows.UI.Notifications;
var currentTime = new Date();
var seconds = 60;
var dueTime = new Date(currentTime.getTime() + seconds * 60 * 1000);
var idNumber = Math.floor(Math.random() * 100000000);  // Generates a unique ID number for the notification.

// Set up the notification text.
var toastXml = Notifications.ToastNotificationManager.getTemplateContent(Notifications.ToastTemplateType.toastText02);
var strings = toastXml.getElementsByTagName("text");
strings[0].appendChild(toastXml.createTextNode(This is a scheduled toast notification));
strings[1].appendChild(toastXml.createTextNode("Received: " + dueTime.toLocaleTimeString()));

// Create the toast notification object.
var toast = new Notifications.ScheduledToastNotification(toastXml, dueTime);
toast.id = "Toast" + idNumber;

// Add to the schedule.
Notifications.ToastNotificationManager.createToastNotifier().addToSchedule(toast);

另請參閱

適用於

ScheduledToastNotification(XmlDocument, DateTime, TimeSpan, UInt32)

Windows 10中已被取代。 在 Windows 8 系統上,建立並初始化 ScheduledToastNotification 的新實例,該實例會在一開始出現之後的指定時間之後重新出現。 在Windows 10上,此函式相當於ScheduledToastNotification (XmlDocument、DateTime) 。 若要在Windows 10中達到相同的延遲間隔行為,您可以在快顯通知上使用按鈕

public:
 ScheduledToastNotification(XmlDocument ^ content, DateTime deliveryTime, TimeSpan snoozeInterval, unsigned int maximumSnoozeCount);
 ScheduledToastNotification(XmlDocument const& content, DateTime const& deliveryTime, TimeSpan const& snoozeInterval, uint32_t const& maximumSnoozeCount);
public ScheduledToastNotification(XmlDocument content, System.DateTimeOffset deliveryTime, System.TimeSpan snoozeInterval, uint maximumSnoozeCount);
function ScheduledToastNotification(content, deliveryTime, snoozeInterval, maximumSnoozeCount)
Public Sub New (content As XmlDocument, deliveryTime As DateTimeOffset, snoozeInterval As TimeSpan, maximumSnoozeCount As UInteger)

參數

content
XmlDocument

定義快顯通知內容的 XML。

deliveryTime
DateTime DateTimeOffset

Windows 應該先顯示快顯通知的日期和時間。 您必須在此時間之前呼叫 AddToSchedule

snoozeInterval
TimeSpan TimeSpan

通知出現之間的時間量。 若要有效,此值不得小於 60 秒,且不超過 60 分鐘。

maximumSnoozeCount
UInt32

unsigned int

uint32_t

顯示此通知的最大次數。 有效值的範圍從 1 到 5。

範例

下列範例顯示排定在一小時內顯示的快顯通知,包括使用此建構函式來建立通知、指定延遲間隔 60 秒,以及最多五次顯示通知。

var Notifications = Windows.UI.Notifications;
var currentTime = new Date();
var seconds = 60;
var dueTime = new Date(currentTime.getTime() + seconds * 60 * 1000);
var idNumber = Math.floor(Math.random() * 100000000);  // Generates a unique ID number for the notification.

// Set up the notification text.
var toastXml = Notifications.ToastNotificationManager.getTemplateContent(Notifications.ToastTemplateType.toastText02);
var strings = toastXml.getElementsByTagName("text");
strings[0].appendChild(toastXml.createTextNode(This is a scheduled toast notification));
strings[1].appendChild(toastXml.createTextNode("Received: " + dueTime.toLocaleTimeString()));

// Create the toast notification object.
var toast = new Notifications.ScheduledToastNotification(toastXml, dueTime, 60 * 1000, 5);
toast.id = "Toast" + idNumber;

// Add to the schedule.
Notifications.ToastNotificationManager.createToastNotifier().addToSchedule(toast);

備註

這種類型的延遲間隔排程快顯通知適用于類似延遲的警示功能。 例如,除非應用程式從排程中明確移除通知,否則通知每隔五分鐘會顯示一次,直到達到延遲計數上限為止。

重要

當使用者透過觸控或按一下啟動通知時,您的應用程式會負責從排程移除通知。 若無法這麼做,可能會導致通知重新出現,直到達到最大延遲計數為止,即使使用者已經處理過。

如果您想要排程長延遲間隔,例如月或年,建議您使用個別排程的快顯通知,而不是此方法。 這可避免日光節約時間或閏年所造成的計時錯誤。

下列程式碼顯示這個方法的呼叫,此呼叫最多三次時,會每隔五分鐘顯示一次 myData 開始的快顯通知。

new ScheduledToastNotification(toast1, myDate, 60000, 3)

另請參閱

適用於