TrySetWallpaperImageAsync() 始终 returns 错误

TrySetWallpaperImageAsync() always returns false

我正在尝试将墙纸设置为我的 Windows 10 设备上的图像:

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;

存储文件创建良好,已尝试使用来自不同文件夹(例如我的图片、资产、LocalState)的各种图像;始终 returns false 且未设置壁纸?我对图片库有 read/write 权限,在调试和发布版本中尝试过 运行。显然其他人也有这个 problem.

您的应用无法设置来自任何文件夹的壁纸。复制 ApplicationData.Current.LocalFolder 中的文件并从那里设置墙纸。 我的代码:

    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;
        }