UserProfilePersonalizationSettings.TrySetWallpaperImageAsync 方法

定义

尝试将指定的图像文件设置为桌面壁纸图像。

public:
 virtual IAsyncOperation<bool> ^ TrySetWallpaperImageAsync(StorageFile ^ imageFile) = TrySetWallpaperImageAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<bool> TrySetWallpaperImageAsync(StorageFile const& imageFile);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<bool> TrySetWallpaperImageAsync(StorageFile imageFile);
function trySetWallpaperImageAsync(imageFile)
Public Function TrySetWallpaperImageAsync (imageFile As StorageFile) As IAsyncOperation(Of Boolean)

参数

imageFile
StorageFile

要设置为桌面背景的图像。

返回

异步操作的结果。 如果成功设置背景图像,则为 true;否则为 false

属性

示例

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

注解

注意

多次设置映像时,新映像文件的名称必须与以前设置的映像不同。 如果使用与上一个映像同名的文件设置新映像,它将失败。

适用于