c# - 在锁定屏幕上显示 UWP 控件

标签 c# uwp toast lockscreen lockscreenwidget

我做了什么

我得到了用户需要能够通过 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/

相关文章:

c# - 具有默认数据的通用对象创建方法

visual-studio - 参数 targetplatformversion 不能为 null - visual studio 2015

android toast 不适合文本

android - 使用 ConnectivityManager 和 NetworkInfo 避免 NullPointerException

android - 如果上下文相同,为什么在 Android 中制作 Toast 的位置很重要?

c# - iTextSharp - 在电子邮件附件中发送内存中的 pdf

c# - 在 C# 中模拟可变参数模板

c# - 与 Visual Studio 界面中的断点位于同一列的浅蓝色矩形的用途是什么?

c# - 如何在 ItemsControl 中设置从 ItemTemplate 到托管容器的绑定(bind)? (UWP)

c# - 垂直对齐以使命令栏内容内的文本框居中