mercoledì 13 febbraio 2013 #

Windows 8 tips : Recuperare informazioni sull’utente

La classe UserInformation contenuta nel namespace Windows.System.UserProfile espone proprietà generiche dell'utente permettendo così il recupero dell'immagine del profilo e informazioni come nome e cognome, consente infine di modificare l'avatar del profilo

Di seguito riepilogo i metodi e la relativa descrizione (Fonte MSDN)

Method

Description

GetAccountPicture

Gets the account picture for the user.

GetDisplayNameAsync

Gets the display name for the user account.

GetDomainNameAsync

Gets the domain name for the user.

GetFirstNameAsync

Gets the user's first name.

GetLastNameAsync

Gets the user's last name.

GetPrincipalNameAsync

Gets the principal name for the user. This name is the User Principal Name (typically the user's address, although this is not always true.)

GetSessionInitiationProtocolUriAsync

Gets the Uniform Resource Identifier (URI) of the session initiation protocol for the user.

SetAccountPictureAsync

Sets the picture for the user's account using an IStorageFile object.

SetAccountPictureFromStreamAsync

Sets the picture for the user's account using an IRandomAccessStream object.

SetAccountPicturesAsync

Sets the pictures for the user's account using an IStorageFile object. Supports adding a small image, large image, and video.

SetAccountPicturesFromStreamsAsync

Sets the pictures for the user's account using an IRandomAccessStream object. Supports adding a small image, large image, and video.

Nell'esempio che segue recupero l'immagine del profilo e il nome completo dell'utente, sul metodo OnNavigatedTo della pagina

protected async override void OnNavigatedTo(NavigationEventArgs e)

{

IRandomAccessStream imageStream = await Windows.System.UserProfile.UserInformation.GetAccountPicture(Windows.System.UserProfile.AccountPictureKind.SmallImage).OpenReadAsync();

BitmapImage UserBmp = new BitmapImage();

UserBmp.SetSource(imageStream);

UserImage.Source = UserBmp;

TbkUserName.Text = await Windows.System.UserProfile.UserInformation.GetDisplayNameAsync();

 

}

Il codice XAML della pagina è il seguente

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">

<Image Width="100" Height="100" x:Name="UserImage" />

<TextBlock Margin="5,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="TbkUserName" Text="Loading..." />

</StackPanel>

 

posted @ lunedì 1 gennaio 0001 00:00 | Feedback (20)