0

I want to display custom text or control on the Windows 10 Lockscreen, when I click on a button. I tried it with an UWP Application.

My goal is something like this:

enter image description here

And the Code I tried:

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);

Also I saw this post and tried it of course, but it wasnt helpfull: Windows Lock Screen display text programmatically C#

Maybe you could help me to achive my goald I thank you in advance

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
wpferr19
  • 21
  • 4
  • I was able to get this to work in a UWP project using the code you posted. In your Windows settings (Notifications & actions), make sure you have "Get notifications from apps and other senders" and "Show notifications on the lock screen" turned on. – Jesse Nov 26 '21 at 16:16
  • @Jesse Thank you for your answer. Everything is turned on, but it still doesnt work :/ – wpferr19 Nov 26 '21 at 17:37
  • @Jesse if I click on the Button, the Notification is shown up but thats not my goal, I want to see something in the Lock Screen if I click on the Button and Lock my PC. I want something like Spotify or the Time and Date. – wpferr19 Nov 26 '21 at 17:39
  • This should be useful since you want to show a custom window on top of the lock screen --> https://stackoverflow.com/a/44406897 – TheCoder Nov 28 '21 at 04:06

1 Answers1

0

The screenshot you post above is smtc that used to show current playing music, for enable it you need to enable the app Background Media Playback, but it only use to show the media info, it can't use to share custom info like you mentioned scenario.

For your scenario, the better way is register your app LockScreen capability like the following.

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

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

And set the app as main toast in the lock screen Setting page -> Personalization -> lock screen -> Choose one app to show detailed status on the lock screen If you have resisted the app, it will show in the apps list.

Code Sample

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);
}
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36