簡體   English   中英

將代碼添加到Toast Notification UWP

[英]Adding code to a Toast Notification UWP

我有一個從項目外部執行的Toast通知(在后台執行)。 在這里你有:

private void SendMessage(string title, string text)
{
    ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    XmlNodeList textElements = toastXml.GetElementsByTagName("text");
    textElements[0].AppendChild(toastXml.CreateTextNode(title));
    textElements[1].AppendChild(toastXml.CreateTextNode(text));
    ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml));
}

我的問題是當我嘗試在用戶點擊toast時執行代碼時,我想從Main項目中執行部分代碼。 有沒有辦法做到這一點?

謝謝

本文中,您可以找到處理來自Toast通知的激活部分
不久:
在toast之后單擊調用的OnActivated事件,您可以檢查參數。
使用新的吐司模板:

protected override void OnActivated(IActivatedEventArgs e)
{
  if (e is ToastNotificationActivatedEventArgs)
  {

  }
}

並使用舊模板(就像我認為你有):

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
   string launchString = args.Arguments
   // ....
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM