<StackPanel>
<Button Content="Set Account Image By File Picker" x:Name="btnSetAccountImageByFilePicker" Click="btnSetAccountImageByFilePicker_Click_1"></Button>
<Button Content="Set Account Image By App Image" x:Name="btnSetAccountImageByAppImage" Click="btnSetAccountImageByAppImage_Click_1"></Button>
<Button Content="Set Account Image By URL" x:Name="btnSetAccountImageByURL" Click="btnSetAccountImageByURL_Click_1"></Button>
</StackPanel>
Step 2: Add below using directive in MainPage.xaml.cs
using
Windows.Storage.Pickers;
using Windows.Storage;
using Windows.System.UserProfile;
using Windows.UI.Popups;
using Windows.Networking.BackgroundTransfer;
Step 3: Create a method SetAccountPicture which will set the account picture using SetAccountPicturesAsync method of UserInformation static class.
SetAccountPicturesAsync takes three parameters, first parameter is for small image, second parameter is for large image and third parameter is for video.
In case of small image, large image or video should be mentioned.
In case of large image, small image will be auto generated.
In case of video, large and small image will be auto generated.
The length of video should be <= 5MB and height and length should be greater than or equal to 448px.
Setting of account picture will fail if it is disallowed in PC settings.
private static async System.Threading.Tasks.Task SetAccountPicture(StorageFile file)
{
SetAccountPictureResult result;
if (file.FileType.Equals(".mp4"))
{
result = await UserInformation.SetAccountPicturesAsync(null, null, file);
}
else
{
result = await UserInformation.SetAccountPicturesAsync(null, file, null);
}
MessageDialog dlg;
if (result == SetAccountPictureResult.Success)
{
dlg = new MessageDialog("Account picture saved successfully.");
}
else
{
dlg = new MessageDialog("Account picture could not be changed.");
}
await dlg.ShowAsync();
}