Windows 8 Store Apps学习(58) 微软账号2014-03-09 cnblogs webabcd介绍重新想象 Windows 8 Store Apps 之 微软账号获取微软账号的用户相关的信息获取或设置微软账号的图片和视频微软账号的验证,和相关信息的获取 示例1、演示如何获取微软账号的用户相关的信息Account/AccountInfo.xaml
<Pagex: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 namelblMsg.Text += "first name: " + await UserInformation.GetFirstNameAsync();lblMsg.Text += Environment.NewLine;// 获取 last namelblMsg.Text += "last name: " + await UserInformation.GetLastNameAsync();lblMsg.Text += Environment.NewLine;}// 如果需要获取 GetDomainNameAsync(), GetPrincipalNameAsync(), GetSessionInitiationProtocolUriAsync() 等信息// 则需要在 Package.appxmanifest 中增加配置 <Capability Name="enterpriseAuthentication" />,且必须使用公司账号上传 app}}}
2、演示如何获取或设置微软账号的图片和视频Account/AccountPicture.xaml
<Pagex: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>