In this article I will talk about setting lock screen background from app in Windows Phone.
Step 1: Create a silverlight for Windows Phone project.
Step 2: Create a image file with resolution 480X800 or more as supported by Windows Phone.
Step 3: Add the image in the project. I have named the image LockImage, you can name it of your choice
Step 4: Add reference of Windows.Phone.System.UserProfile and System.Threading.Tasks in MainPage.Xaml.cs.
Step 5: Create a method IsLockScreenProvidedByCurrentApplicationt to find out whether the app is current background screen provider.
Static class LockScreenManager of Windows.Phone.System.UserProfile has
IsProvidedByCurrentApplication readonly property which indicates whether app is current lock screen provider. Return type is bool.
RequestAccessAsync method sets the current app as the lock screen background provider. Return type is IAsyncOperation<LockScreenRequestResult>
private async Task<bool> IsLockScreenProvidedByCurrentApplicationt()
bool isProvider = LockScreenManager.IsProvidedByCurrentApplication;
// Prompt the user for permission, if current app is not provider of lock screen.
// RequestAccessAsync can not be invoked from background agent.
LockScreenRequestResult op = await LockScreenManager.RequestAccessAsync();
isProvider = op == LockScreenRequestResult.Granted;
Step 6: Create SetLockScreenWallPaper SetLockScreenWallPaper which will set the lock screen background.
Static class LockScreen of Windows.Phone.System.UserProfile has
GetImageUri method which gets the URI of current lock screen background. Return type is URI.
SetImageUri method sets the URI of the current lock screen background, it takes URI as parameter.
private async void SetLockScreenWallPaper(string filePathOfTheImage, bool isAppResource)
if (await IsLockScreenProvidedByCurrentApplicationt())
// ms-appdata points to the root of the local app data folder.
// ms-appx points to the Local app install folder, to reference resources bundled in the XAP package.
var schema = isAppResource ? "ms-appx:///" : "ms-appdata:///Local/";
var uri = new Uri(schema + filePathOfTheImage, UriKind.Absolute);
// Set the lock screen background image.
// Get the URI of the lock screen background image.
var currentImage = LockScreen.GetImageUri();
MessageBox.Show("Permission denied by user to set the background.");
catch (System.Exception ex)
Step 7: Create a btnLockScreen_Click_1 event handler which will invoke SetLockScreenWallPaper.
private void btnLockScreen_Click_1(object sender, RoutedEventArgs e)
Step 8: Now run the application.
1. Click on Set Lock Screen and you will be prompted with Set as lock screen? message like shown below.
2. On click of Yes the lock screen background will be set as shown below, the lock screen image will vary based on the image. To check on device lock it using power button and if you are running on emulator press F12 twice.
3. Now go to Setting then Lock Screen, you will see app name in Background as shown below. I have name the app LockScreen_1.
This ends the article of setting lock screen background from app in Windows Phone