UWP吐司通知 - XML工作,AdaptiveText不(Windows 10,Visual Studio 2017)

问题描述:

我有我的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”方法中删除“我的应用程序”时它起作用吗? –

原来,ExpirationTime = DateTime.Now.AddDays(model.Expiration)是问题所在。它被送进0,结果Toast在它被发送的那一刻过期了,从不显示。