【问题标题】:Windows Lock Screen, add Text programmaticallyWindows 锁屏,以编程方式添加文本
【发布时间】:2022-01-04 15:40:02
【问题描述】:

我想在单击按钮时在 Windows 10 锁屏上显示自定义文本或控件。我用 UWP 应用程序尝试过。

我的目标是这样的:

我尝试过的代码:

ToastContent content = new ToastContent()
            {
                //Duration = ToastDuration.Long,
                Scenario = ToastScenario.Reminder,
                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);

当然我也看到了这个帖子并尝试过,但它没有帮助:Windows Lock Screen display text programmatically C#

也许你可以帮助我实现我的目标 提前谢谢你

【问题讨论】:

  • 我能够使用您发布的代码使其在 UWP 项目中工作。在您的 Windows 设置(通知和操作)中,确保您已开启“从应用和其他发件人获取通知”和“在锁定屏幕上显示通知”。
  • @Jesse 谢谢你的回答。一切都打开了,但它仍然不起作用:/
  • @Jesse 如果我点击按钮,会显示通知,但这不是我的目标,如果我点击按钮并锁定我的电脑,我想在锁定屏幕上看到一些东西。我想要 Spotify 或时间和日期之类的东西。
  • 这应该很有用,因为您想在锁定屏幕顶部显示自定义窗口 --> stackoverflow.com/a/44406897

标签: c# wpf windows uwp


【解决方案1】:

你上面的截图是smtc,用来显示当前播放的音乐,要启用它需要启用应用程序Background Media Playback,但它只用于显示媒体信息,不能用于分享像您提到的场景一样的自定义信息。

对于您的方案,更好的方法是注册您的应用 LockScreen 功能,如下所示。

<Applications>
   <Application Id="App"
     Executable="$targetnametoken$.exe"
     EntryPoint="xxxxx.UWP.App">
    
     .......

       <uap:LockScreen BadgeLogo="Assets\BadgeLogo.png" Notification="badgeAndTileText"/>
     </uap:VisualElements>
   </Application>
 </Applications>

并在锁屏中设置应用为主吐司设置页面->个性化->锁屏->选择一个应用在锁屏上显示详细状态它会显示在应用列表中。

代码示例

private void Button_Click(object sender, RoutedEventArgs e)
{
    TileContent content = new TileContent()
    {
        Visual = new TileVisual()
        {
            LockDetailedStatus1 = "Hello world",
          
            TileWide = new TileBinding() { }
        }
    };
    var notification = new TileNotification(content.GetXml());
    TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
}

【讨论】:

  • 首先,感谢您的回答。我昨天试过了,一整天。它没有用,我不知道为什么:/
  • 你在设置页面开启应用了吗?
  • 我尝试注册我的应用程序但我无法成功我搜索了很多小时但没有运气。您能否描述一下我如何注册我的应用程序。因为我在注册之前在设置页面中看不到这个应用程序(我认为)
  • 现在我可以在设置页面中启用它,但它没有改变任何东西:/
  • 你需要锁屏等待两秒左右,toast会显示在左下角
猜你喜欢
  • 1970-01-01
  • 2011-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-08
  • 1970-01-01
  • 2012-12-13
  • 2011-02-28
相关资源
最近更新 更多