我做了什么
我得到了用户需要能够通过 Windows 锁定屏幕启动我的应用程序的要求。在搜索 www 后发现从锁定屏幕连接热键非常困难(如果不是不可能的话)。
然后我找到this post它使用
Microsoft.Toolkit.Uwp.Notifications.TileContent
向锁定屏幕发送通知。
我找不到向 TileContent
添加一些按钮或类似控件的方法,所以我尝试了
Microsoft.Toolkit.Uwp.Notifications.ToastContent
我成功添加了一个按钮,我可以像这样显示 ToastNotification
ToastContent content = new ToastContent()
{
Duration = ToastDuration.Long,
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Attribution = new ToastGenericAttributionText()
{
Text = "Hello World"
}
}
},
Actions = new ToastActionsCustom()
{
Buttons = {
new ToastButton ("mycontent", "myargs")
}
}
};
var notification = new ToastNotification(content.GetXml());
ToastNotificationManager.CreateToastNotifier().Show(notification);
使用这种方法时,我遇到了 ToastNotification
在特定时间后消失的问题。 ToastContent.Duration
属性不能设置为“连续”或类似的值。
问题
- 有没有办法持续显示
ToastNotification
? - 如果没有,是否有另一种方法可以像 Spotify 小部件那样通过按钮(或其他控件)通过锁定屏幕触发我的应用程序。 (参见 linked post 的屏幕截图)
最佳答案
没有支持的方法可以将按钮添加到锁定屏幕 - 只有文本。
Spotify“小部件”就是“正在播放”用户界面,仅与媒体应用相关。
您可以通过将 toast 变成提醒来让 toast “持续”显示。这将使 toast 一直显示在屏幕上,直到用户将其关闭。
ToastContent content = new ToastContent()
{
Scenario = ToastScenario.Reminder,
Visual = new ToastVisual()
但是,为此使用 toasts 可能是对 toast 通知的滥用。但这在您的场景中可能有意义。
关于c# - 在锁定屏幕上显示 UWP 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48157662/