【问题标题】:How can I show custom alerts in UWP or WPF application?如何在 UWP 或 WPF 应用程序中显示自定义警报?
【发布时间】:2020-06-12 14:33:12
【问题描述】:

我需要显示或发送通知的 UWP 应用程序或 wpf 应用程序,这些通知也会在锁定屏幕和屏幕保护程序上全屏显示(简而言之,覆盖所有条件并显示警报)。

我在 UWP 中创建了一个使用微软提供的ToastNotification 的示例应用,但我们无法自定义它的大小。

 public static void ShowAlertNotification()
        {
            var toastContent = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = "High Alert Message"
                            },
                            new AdaptiveText()
                            {
                                Text = "Alert from Notifications App"
                            },
                            new AdaptiveImage()
                            {
                                Source = "Assets/caution.png"
                            }
                        }
                    }
                },
                Actions = new ToastActionsCustom()
                {
                    Buttons =
                    {
                        new ToastButton("Ignore", "action=ignore&callId=938163")
                        {
                            ActivationType = ToastActivationType.Protocol,
                            ImageUri = "Assets/stop.png"
                        },
                        new ToastButton("Acknowledged", "action=answer&callId=938163")
                        {
                            ActivationType = ToastActivationType.Foreground,
                            ImageUri = "Assets/correct.png"
                        }
                    }
                },
                Launch = "action=answer&callId=938163",
                Scenario = ToastScenario.IncomingCall,
                DisplayTimestamp = DateTime.Now,
            };

            // Create the toast notification
            var toastNotif = new ToastNotification(toastContent.GetXml());

            // And send the notification
            ToastNotificationManager.CreateToastNotifier().Show(toastNotif);
        }

默认ToastNotification 具有预定义类型,如日历、呼叫等。但我需要它来全屏显示。

我也尝试过在全屏模式下创建 win 表单,而不是使用服务调用它,但我认为这不是可取的。

我需要这种类型的学校应用,可以向家长发送紧急警报。

那么对此有什么想法或建议吗?

提前致谢。

【问题讨论】:

  • 我们无法在 UWP 中指定 toast 的宽度和高度,因此您无法将其设置为全屏。您可以使用弹出窗口并将其大小设置为全屏以在使用应用程序时显示它,但它不会显示在锁定屏幕上。
  • 您实际上可以“构建”您的适当通知屏幕,并能够根据需要对其进行自定义,并使您的代码中可见或不可见。 (可取消等)

标签: c# wpf uwp


【解决方案1】:

使用Azure Notification Hub,您可以向移动 UWP 应用发送 toast 通知,即使应用未运行,您也会收到该信息。

在 UWP 中,toast 通知的视觉外观取决于运行应用的实际设备。不过,您可以使用this article 中的语法描述对其进行扩展,但是正如 Faywang - MSFT 在 cmets 中提到的那样,

你不能设置成全屏(因为我们不能指定toast的宽高)

【讨论】:

    猜你喜欢
    • 2011-08-18
    • 2019-10-24
    • 1970-01-01
    • 2018-10-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    相关资源
    最近更新 更多