UserProfilePersonalizationSettings.TrySetLockScreenImageAsync(StorageFile) UserProfilePersonalizationSettings.TrySetLockScreenImageAsync(StorageFile) UserProfilePersonalizationSettings.TrySetLockScreenImageAsync(StorageFile) UserProfilePersonalizationSettings.TrySetLockScreenImageAsync(StorageFile) UserProfilePersonalizationSettings.TrySetLockScreenImageAsync(StorageFile) Method

Definition

Attempts to set the specified image file as the lock screen background image.

public : IAsyncOperation<Platform::Boolean> TrySetLockScreenImageAsync(StorageFile imageFile)
IAsyncOperation<bool> TrySetLockScreenImageAsync(StorageFile imageFile) const;
public IAsyncOperation<bool> TrySetLockScreenImageAsync(StorageFile imageFile)
Public Function TrySetLockScreenImageAsync(imageFile As StorageFile) As IAsyncOperation(Of bool)
Windows.System.UserProfile.UserProfilePersonalizationSettings.trySetLockScreenImageAsync(imageFile).done( /* Your success and error handlers */ );

Parameters

imageFile
StorageFile StorageFile StorageFile

The image to set as the lock screen background.

Returns

The result of the async operation. true if the background image was set successfully; otherwise, false.

Examples

using Windows.System.UserProfile;

// Pass in a relative path to a file inside the local appdata folder 
async Task<bool> SetWallpaperAsync(string localAppDataFileName) 
{ 
    bool success = false;
    if (UserProfilePersonalizationSettings.IsSupported())
    {
        var uri = new Uri("ms-appx:///Local/" + localAppDataFileName);
        StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);
        UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
        success = await profileSettings.TrySetLockScreenImageAsync(file);
    }
    return success;
} 

Remarks

Note

For the mobile device family, you can only set a lock screen image that is smaller than 2 megabyte (MB). Attempting to set a lock screen image that is larger fails, even though the async operation returns true.

Note

When you set an image more than once, the new image file must have a different name than the previously set image. If you set a new image using a file with the same name as the previous image, it will fail.