介紹
重新想象 Windows 8 Store Apps 之 微軟帳號
擷取微軟帳號的使用者相關的資訊
擷取或設定微軟帳號的圖片和視頻
微軟帳號的驗證,和相關資訊的擷取
樣本
1、示範如何擷取微軟帳號的使用者相關的資訊
Account/AccountInfo.xaml
<Page x:Class="XamlDemo.Account.AccountInfo" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:XamlDemo.Account" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="120 0 0 0"> <TextBlock Name="lblMsg" FontSize="14.667" /> </StackPanel> </Grid></Page>
Account/AccountInfo.xaml.cs
/* * 示範如何擷取微軟帳號的使用者相關的資訊 */ using System;using Windows.System.UserProfile;using Windows.UI.Xaml.Controls;using Windows.UI.Xaml.Navigation; namespace XamlDemo.Account{ public sealed partial class AccountInfo : Page { public AccountInfo() { this.InitializeComponent(); } protected async override void OnNavigatedTo(NavigationEventArgs e) { if (UserInformation.NameAccessAllowed) // 是否允許訪問使用者名稱 { // 擷取用於顯示的名稱 lblMsg.Text = "display name: " + await UserInformation.GetDisplayNameAsync(); lblMsg.Text += Environment.NewLine; // 擷取 first name lblMsg.Text += "first name: " + await UserInformation.GetFirstNameAsync(); lblMsg.Text += Environment.NewLine; // 擷取 last name lblMsg.Text += "last name: " + await UserInformation.GetLastNameAsync(); lblMsg.Text += Environment.NewLine; } // 如果需要擷取 GetDomainNameAsync(), GetPrincipalNameAsync(), GetSessionInitiationProtocolUriAsync() 等資訊 // 則需要在 Package.appxmanifest 中增加配置 <Capability Name="enterpriseAuthentication" />,且必須使用公司帳號上傳 app } }}
2、示範如何擷取或設定微軟帳號的圖片和視頻
Account/AccountPicture.xaml
<Page x:Class="XamlDemo.Account.AccountPicture" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:XamlDemo.Account" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="120 0 0 0"> <StackPanel Orientation="Horizontal"> <Button x:Name="btnSetImage" Content="設定當前微軟帳號的圖片(可以分別指定小圖,大圖,視頻)" Click="btnSetImage_Click_1" /> </StackPanel> <StackPanel Orientation="Horizontal" Margin="0 10 0 0"> <Image x:Name="imgSmall" Width="96" Height="96" HorizontalAlignment="Left" /> <Image x:Name="imgLarge" Width="448" Height="448" Margin="10 0 0 0" HorizontalAlignment="Left" /> <MediaElement x:Name="mediaElement" Width="200" Height="200" Margin="10 0 0 0" HorizontalAlignment="Left" /> </StackPanel> </StackPanel> </Grid></Page>