鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > .net技术 > WinRT/Metro > >

重新想象 Windows 8 Store Apps (58)

来源:互联网 作者:佚名 时间:2013-11-15 14:36
重新想象 Windows 8 Store Apps (58) - 微软账号Posted on [源码下载] 重新想象 Windows 8 Store Apps (58) - 微软账号 作者:webabcd 介绍 重新想象 Windows 8 Store Apps 之微软账号 示例 1、演示如何获取微软账号的用户相关的信息 Account/AccountInfo.xa

重新想象 Windows 8 Store Apps (58) - 微软账号 Posted on

[源码下载]


重新想象 Windows 8 Store Apps (58) - 微软账号



作者:webabcd


介绍
重新想象 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

Account/AccountInfo.xaml.cs

/* * 演示如何获取微软账号的用户相关的信息 */ using System; using Windows.System.UserProfile; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; namespace XamlDemo.Account { AccountInfo : Page { public AccountInfo() { this.InitializeComponent(); } OnNavigatedTo(NavigationEventArgs e) { if (UserInformation.NameAccessAllowed) // 是否允许访问用户名 { // 获取用于显示的名称 lblMsg.Text = + await UserInformation.GetDisplayNameAsync(); lblMsg.Text += Environment.NewLine; // 获取 first name lblMsg.Text += + await UserInformation.GetFirstNameAsync(); lblMsg.Text += Environment.NewLine; // 获取 last name lblMsg.Text += + await UserInformation.GetLastNameAsync(); lblMsg.Text += Environment.NewLine; } // 如果需要获取 GetDomainNameAsync(), GetPrincipalNameAsync(), GetSessionInitiationProtocolUriAsync() 等信息 // 则需要在 Package.appxmanifest 中增加配置 <Capability />,且必须使用公司账号上传 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

Account/AccountPicture.xaml.cs

/* * 演示如何获取或设置微软账号的图片和视频 */ using System; using Windows.Storage; using Windows.Storage.Pickers; using Windows.Storage.Streams; using Windows.System.UserProfile; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Xaml.Navigation; using XamlDemo.Common; namespace XamlDemo.Account { AccountPicture : Page { public AccountPicture() { this.InitializeComponent(); } OnNavigatedTo(NavigationEventArgs e) { GetSmallImage(); GetLargeImage(); GetVideo(); // 当微软账号的图片或视频发生变化时触发的事件 UserInformation.AccountPictureChanged += PictureChanged; } OnNavigatedFrom(NavigationEventArgs e) { UserInformation.AccountPictureChanged -= PictureChanged; } private void PictureChanged(object sender, object e) { GetSmallImage(); GetLargeImage(); GetVideo(); } GetSmallImage() { // UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) - 获取当前微软账号的小图片 StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile; if (image != null) { try { IRandomAccessStream imageStream = await image.OpenReadAsync(); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(imageStream); imgSmall.Source = bitmapImage; } finally { } } } GetLargeImage() { // UserInformation.GetAccountPicture(AccountPictureKind.LargeImage) - 获取当前微软账号的大图片 StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.LargeImage) as StorageFile; if (image != null) { try { IRandomAccessStream imageStream = await image.OpenReadAsync(); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(imageStream); imgLarge.Source = bitmapImage; } finally { } } } GetVideo() { // UserInformation.GetAccountPicture(AccountPictureKind.Video) - 获取当前微软账号的视频 StorageFile video = UserInformation.GetAccountPicture(AccountPictureKind.Video) as StorageFile; if (video != null) { try { IRandomAccessStream videoStream = await video.OpenAsync(FileAccessMode.Read); mediaElement.SetSource(videoStream, ); } finally { } } } btnSetImage_Click_1(object sender, RoutedEventArgs e) { if (Helper.EnsureUnsnapped()) { FileOpenPicker imagePicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary, FileTypeFilter = { , , , } }; StorageFile imageFile = await imagePicker.PickSingleFileAsync(); if (imageFile != null) { // UserInformation.SetAccountPicturesAsync() - 设置微软账号的图片和视频(可以分别指定:小图片,,大图片,视频) SetAccountPictureResult result = await UserInformation.SetAccountPicturesAsync(null, imageFile, null); if (result == SetAccountPictureResult.Success) { } } } } } }


3、演示微软账号的验证,和相关信息的获取
Account/AccountAuthorization.xaml

网友评论
<