代码之家  ›  专栏  ›  技术社区  ›  Pooran

UWP通知不会弹出,但可以在通知选项卡中找到

  •  0
  • Pooran  · 技术社区  · 4 年前

    默认日历应用程序的UWP通知首先弹出,它们也将出现在通知选项卡上。如何实现这一点?

    默认情况下,我们的应用程序通知会落在通知选项卡上,而不会弹出。 对于少数通知,我们将NotifyPriority设置为Max。即使它们也会在没有正常弹出窗口的情况下出现在通知栏上

            public void Notify(string title, string content, int Id, bool trackTap = false, bool IsDetailed = false, string extraContent = "", NotifyPriority priority = NotifyPriority.Normal, string returnData = "")
        {
            try
            {
                ToastVisual visual = new ToastVisual
                {
                    BindingGeneric = new ToastBindingGeneric
                    {
                        Children =
                        {
                            new AdaptiveText
                            {
                                Text = title,
                                HintStyle = AdaptiveTextStyle.Title
                            },
                            new AdaptiveText
                            {
                                Text = content
                            }
                        }
                    }
                };
    
                if (IsDetailed)
                {
                    visual.BindingGeneric.Children.Add(new AdaptiveText { Text = extraContent });
                }
    
                ToastContent toastContent = new ToastContent
                {
                    Visual = visual
                };
    
                if (!string.IsNullOrEmpty(returnData))
                {
                    toastContent.Launch = returnData;
                }
    
                var toast = new ToastNotification(toastContent.GetXml())
                {
                    Tag = Id.ToString(),
                    Group = "XXXX"
                };
    
                if (priority == NotifyPriority.Max)
                {
                    toast.Priority = ToastNotificationPriority.High;
                    toast.ExpiresOnReboot = false;
                }
    
                ToastNotificationManager.CreateToastNotifier().Show(toast);
            }
            catch (Exception ex)
            {
                LoggerService.Instance.TrackError(ex);
            }
        }
    
    0 回复  |  直到 4 年前