4

What I have done

I got the requirement that the user needs to be able to start my application through the windows lock screen. After searching the www it turned out to hook up hotkeys from the lock screen is very difficult (if not impossible).
Then I found this post which uses

 Microsoft.Toolkit.Uwp.Notifications.TileContent  

to send notifications to the lock screen.
I found no way to add some buttons or similar controls to the TileContent so I tried the

Microsoft.Toolkit.Uwp.Notifications.ToastContent

I successfully added a button and I was possible to show the ToastNotification like this

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

With this approach I have the problem the ToastNotification disapears after a specific amount of time. The ToastContent.Duration property cannot be set to "continuously" or something like that.

Question

  • Is there a way to continuously display the ToastNotification?
  • If not, is there another way to trigger my application through the lock screen via buttons (or other controls) like the Spotify widget does it. (see screenshot of the linked post)
HaaLeo
  • 10,065
  • 3
  • 44
  • 55

2 Answers2

3

There's no supported way to add buttons to the lock screen - only text.

The Spotify "widget" is simply the Now Playing UI, which is only relevant for media apps.

You can make a toast "continuously" display by changing it into a reminder. That'll make the toast stay on screen till the user dismisses it.

ToastContent content = new ToastContent()
{
    Scenario = ToastScenario.Reminder,
    Visual = new ToastVisual()

However, using toasts for this is likely an abuse of toast notifications. But it might make sense in your scenario.

Andrew Leader
  • 975
  • 6
  • 13
  • Thank you for your answer. This helps to display the `ToastNotification` as long as I click on its body (non of the buttons). When the body of the notification is clicked, windows switches to the log-in screen and the notification is no longer displayed. Is there a way to prevent this behavior? – HaaLeo Jan 10 '18 at 08:04
  • Clicking the toast activates your app (which requires the user to log in). You can have clicking the toast activate a background instead by setting the `ActivationType` of the `ToastContent` to `Background`, and then your background task could pop another toast in response to the user clicking it. – Andrew Leader Jan 10 '18 at 20:43
0

If you only want users to be able to access your single app (e.g. for a kiosk in a public place), you can use Assigned Access / Kiosk Mode. Here's some documentation links:

robertos
  • 1,810
  • 10
  • 12