Share via


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

注釈

注意

イメージを複数回設定する場合、新しいイメージ ファイルの名前は、前に設定したイメージとは異なる名前にする必要があります。 前のイメージと同じ名前のファイルを使用して新しいイメージを設定すると、失敗します。

適用対象