Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Create a LockScreen Preview Settings Page for Windows Phone

From Wiki
Jump to: navigation, search

This article explains how to create a Lockscreen settings page that offers a preview of the lockscreen templates to the user

WP Metro Icon UI.png
WP Metro Icon Tools.png
WP Metro Icon WP8.png
Article Metadata
Code ExampleTested with
Devices(s): Nokia Lumia 820, Nokia Lumia 920
Compatibility
Platform(s): Windows Phone 8
Windows Phone 8
Article
Created: I Jones (30 May 2013)
Last edited: hamishwillee (02 Jul 2013)

Contents

Introduction

The main features of this settings page will be the ability to check if the current application is the current lockscreen provider, make the application the lockscreen provider and show a preview of the different templates available for the lockscreen.

LockscreenSettings.png

Checking the current lockscreen provider

Lets look at displaying to the user if the application is the current lockscreen provider. Firstly create a new Windows Phone 8 application, open MainPage.xaml and add a new TextBlock to the page called tbProvider. Also add a new ApplicationBar button called btnAccept. In the code behind, add the following code:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
SetupLockscreenPage();
}
 
private void SetupLockscreenPage()
{
var isProvider = Windows.Phone.System.UserProfile.LockScreenManager.IsProvidedByCurrentApplication;
 
if (isProvider)
{
tbProvider.Text = string.Format("{0} is your current lock screen provider", "[APP NAME]");
}
else
{
tbProvider.Text = string.Format("{0} is not your current lock screen provider", "[APP NAME]");
}
}

The preceding code references "[APP NAME]", this is a placeholder and will need to be replaced with you own app's name.

Making the app a lockscreen provider

Now lets look at setting the current application to the lockscreen provider. In the code behind, add the following code:

public static async Task CheckLockscreenPermissions()
{
var isProvider = Windows.Phone.System.UserProfile.LockScreenManager.IsProvidedByCurrentApplication;
if (!isProvider)
{
// If you're not the provider, this call will prompt the user for permission.// Calling RequestAccessAsync from a background agent is not allowed.
var op = await Windows.Phone.System.UserProfile.LockScreenManager.RequestAccessAsync();
 
// Only do further work if the access was granted.
isProvider = op == Windows.Phone.System.UserProfile.LockScreenRequestResult.Granted;
}
 
return isProvider;
}
 
private async void BtnAccept_OnClick(object sender, EventArgs e)
{
if (await CheckLockscreenPermissions())
{
//Save settings details here
}
}

This code allows us to check and set the application to the current provider when saving the settings.

Creating a lockscreen preview

Finally lets look at how we can implement a lockscreen preview for our lockcreen templates. There’s an experimental control by Scott Lovegrove (twitter) called LockscreenPreview which is part of the latest coding4fun source on codeplex (find it here). It's currently part of the experimental branch, but does include a working demo.

Using the control is simple: you supply it with your image and some text and it mimics the lockscreen for you. Here's an example of how to setup the LockscreenPreview control:

<controls:LockScreenPreview
Width="200"
TextLine1="line1 "
TextLine2="line2"
TextLine3="line3"
LockScreenImageSource="/Assets/trex_360width.jpg"/>

To use these in our settings page, we simply wrap them in a radiobutton and apply a custom style to show the selected item.

Summary

As you can see, the finished page allows you to easily have all your lockscreen logic in one page or it can be used in conjunction with a Background Agent to allow users to customise your application lockscreen and have visual feedback before doing it.

Source Code

You can find the running source code of application presented in this article on below links.

This page was last modified on 2 July 2013, at 05:29.
65 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×