I'm trying to set the wallpaper to an image on my Windows 10 device:
var fileName = postInf.title + ".jpg";
BitmapImage img = new BitmapImage();
bool success = false;
if (UserProfilePersonalizationSettings.IsSupported())
{
// read from pictures library
var pictureFile = await KnownFolders.PicturesLibrary.GetFileAsync(fileName);
using (var pictureStream = await pictureFile.OpenAsync(FileAccessMode.Read))
{
img.SetSource(pictureStream);
}
UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
success = await profileSettings.TrySetWallpaperImageAsync(pictureFile);
}
return success;
The storagefile is created fine, have tried with various images from various folders (eg My Pictures, Assets, LocalState); always returns false and wallpaper is not set? I have read/write permissions to pictures library, have tried running in debug and release versions. Apparently others are also having this problem .
Your app can't set wallpapers from any folder. Copy file in ApplicationData.Current.LocalFolder and set wallpaper from there. My code:
if (list.SelectedIndex != -1)
{
var data = list.SelectedItem as ThumbItem;
StorageFile newFile = await data.File.CopyAsync(ApplicationData.Current.LocalFolder);
await SetWallpaperAsync(newFile);
}
async Task<bool> SetWallpaperAsync(StorageFile fileItem)
{
bool success = false;
if (UserProfilePersonalizationSettings.IsSupported())
{
UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
success = await profileSettings.TrySetWallpaperImageAsync(fileItem);
}
return success;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.