【发布时间】: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 的宽度和高度,因此您无法将其设置为全屏。您可以使用弹出窗口并将其大小设置为全屏以在使用应用程序时显示它,但它不会显示在锁定屏幕上。
-
您实际上可以“构建”您的适当通知屏幕,并能够根据需要对其进行自定义,并使您的代码中可见或不可见。 (可取消等)