共用方式為


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

備註

注意

當您多次設定映射時,新的影像檔必須具有與先前設定映射不同的名稱。 如果您使用與上一個映射同名的檔案來設定新映射,它將會失敗。

適用於