C# TrySetWallpaperImageAsync()始终返回false

C# TrySetWallpaperImageAsync()始终返回false,c#,windows-10,uwp,C#,Windows 10,Uwp,我正在尝试将壁纸设置为Windows 10设备上的图像: var fileName = postInf.title + ".jpg"; BitmapImage img = new BitmapImage(); bool success = false; if (UserProfilePersonalizationSettings.IsSupported()) { // read from pictures library var pictureFile = await Know

我正在尝试将壁纸设置为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;

storagefile创建得很好,已尝试使用不同文件夹中的各种图像(例如,我的图片、资产、LocalState);是否始终返回false且未设置墙纸?我拥有图片库的读/写权限,并尝试在调试和发布版本中运行。显然其他人也有这种情况。

你的应用程序无法从任何文件夹设置壁纸。复制ApplicationData.Current.local文件夹中的文件,并从中设置墙纸。 我的代码:

if(list.SelectedIndex!=-1)
{
var data=list.SelectedItem作为拇指项;
StorageFile newFile=wait data.File.copyanc(ApplicationData.Current.LocalFolder);
等待setwallparasync(newFile);
}
异步任务setWallparAsync(StorageFile文件项)
{
布尔成功=假;
if(UserProfilePersonalizationSettings.IsSupported())
{
UserProfilePersonalizationSettings=UserProfilePersonalizationSettings.Current;
成功=等待profileSettings.TrySetWallpaperImageAsync(fileItem);
}
回归成功;
}

没错,我不知道你必须先将文件保存到本地文件夹,然后才能将其设置为壁纸。谢谢
    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;
        }