2017-09-13 151 views
1

我有我的Toasts設置爲在後臺任務中運行。如果我將XML定義爲敬酒的「舊」方式,那麼一切正常。下面是該代碼:UWP吐司通知 - XML工作,AdaptiveText不(Windows 10,Visual Studio 2017)

var template = ToastTemplateType.ToastText02; 
var xml = ToastNotificationManager.GetTemplateContent(template); 
var elements = xml.GetElementsByTagName("text"); 
var text = xml.CreateTextNode(model.Title); 
elements[0].AppendChild(text); 
var toast = new ToastNotification(xml); 
ToastNotificationManager.CreateToastNotifier("My App").Show(toast); 

如果我嘗試使用AdaptiveText版本,它不運行。事件查看器日誌顯示已發送成功的Toast消息(與第一個事件一樣),但不會顯示Toast。這裏是(microsoft.com上直接從教程貼我複製/),該代碼:

var content = new ToastContent() 
{ 
    Launch = "app-defined-string", 

    Visual = new ToastVisual() 
    { 
     BindingGeneric = new ToastBindingGeneric() 
     { 
      Children = 
      { 
       new AdaptiveText() 
       { 
        Text = "Photo Share" 
       }, 

       new AdaptiveText() 
       { 
        Text = "Andrew sent you a picture" 
       }, 

       new AdaptiveText() 
       { 
        Text = "See it in full size!" 
       }, 

       new AdaptiveImage() 
       { 
        Source = "https://unsplash.it/360/180?image=1043" 
       } 
      }, 

      AppLogoOverride = new ToastGenericAppLogo() 
      { 
       Source = "https://unsplash.it/64?image=883", 
       HintCrop = ToastGenericAppLogoCrop.Circle 
      } 
     } 
    } 
}; 

var toast = new Windows.UI.Notifications.ToastNotification(content.GetXml()) 
{ 
    ExpirationTime = DateTime.Now.AddDays(model.Expiration) 
}; 
toast.Failed += (o, args) => 
{ 
    var message = args.ErrorCode; 
}; 

Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier("My App").Show(toast); 

我有OS構建15063 - 同我的目標爲應用程序。我有一個模板10項目發生這種情況,所以我嘗試製作一個新的非模板10項目,但問題依然存在。我也嘗試使用NuGet的NotificationExtensions.10庫,或者Windows.UI.Notifications/Microsoft.Toolkit.Uwp.Notifications;沒有區別。

+0

當您在「CreateToastNotifier」方法中刪除「我的應用程序」時它起作用嗎? –

回答

0

原來,ExpirationTime = DateTime.Now.AddDays(model.Expiration)是問題所在。它被送進0,結果Toast在它被髮送的那一刻過期了,從不顯示。