UserProfilePersonalizationSettings
UserProfilePersonalizationSettings
UserProfilePersonalizationSettings
UserProfilePersonalizationSettings
Class
Definition
Provides properties and methods to manage the user's desktop wallpaper and lock screen background image.
public : sealed class UserProfilePersonalizationSettings : IUserProfilePersonalizationSettingspublic sealed class UserProfilePersonalizationSettings : IUserProfilePersonalizationSettingsPublic NotInheritable Class UserProfilePersonalizationSettings Implements IUserProfilePersonalizationSettings// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
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
To get an instance of this class, call the Current method.
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.
Properties
Current Current Current Current
Gets the current instance of UserProfilePersonalizationSettings.
public : static UserProfilePersonalizationSettings Current { get; }public static UserProfilePersonalizationSettings Current { get; }Public Static ReadOnly Property Current As UserProfilePersonalizationSettings// You can use this property in JavaScript.
Methods
IsSupported() IsSupported() IsSupported() IsSupported()
Gets a value that indicates whether changing the desktop and lock screen images is supported on the current device.
public : static PlatForm::Boolean IsSupported()public static bool IsSupported()Public Static Function IsSupported() As bool// You can use this method in JavaScript.
true if changing the desktop and lock screen images is supported; otherwise, false.
TrySetLockScreenImageAsync(StorageFile) TrySetLockScreenImageAsync(StorageFile) TrySetLockScreenImageAsync(StorageFile) TrySetLockScreenImageAsync(StorageFile)
Attempts to set the specified image file as the lock screen background image.
public : IAsyncOperation<PlatForm::Boolean> TrySetLockScreenImageAsync(StorageFile imageFile)public IAsyncOperation<bool> TrySetLockScreenImageAsync(StorageFile imageFile)Public Function TrySetLockScreenImageAsync(imageFile As StorageFile) As IAsyncOperation( Of bool )// You can use this method in JavaScript.
- imageFile
- StorageFile StorageFile StorageFile StorageFile
The image to set as the lock screen background.
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.
TrySetWallpaperImageAsync(StorageFile) TrySetWallpaperImageAsync(StorageFile) TrySetWallpaperImageAsync(StorageFile) TrySetWallpaperImageAsync(StorageFile)
Attempts to set the specified image file as the desktop wallpaper image.
public : IAsyncOperation<PlatForm::Boolean> TrySetWallpaperImageAsync(StorageFile imageFile)public IAsyncOperation<bool> TrySetWallpaperImageAsync(StorageFile imageFile)Public Function TrySetWallpaperImageAsync(imageFile As StorageFile) As IAsyncOperation( Of bool )// You can use this method in JavaScript.
- imageFile
- StorageFile StorageFile StorageFile StorageFile
The image to set as the desktop background.
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.TrySetWallpaperImageAsync(file);
}
}
Remarks
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.