背水一战 Windows 10 (82) - 用户和账号: 获取用户的信息, 获取用户的同意
2021-02-10 06:20
标签:package value ipa microsoft soft call sys span logs [源码下载] 作者:webabcd 示例 UserAndAccount/UserInfo.xaml.cs UserAndAccount/UserVerifier.xaml.cs OK 背水一战 Windows 10 (82) - 用户和账号: 获取用户的信息, 获取用户的同意 标签:package value ipa microsoft soft call sys span logs 原文地址:https://www.cnblogs.com/lonelyxmas/p/8527058.html
介绍
背水一战 Windows 10 之 用户和账号
1、演示如何获取用户的信息
UserAndAccount/UserInfo.xamlPage
x:Class="Windows10.UserAndAccount.UserInfo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.UserAndAccount"
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="10 0 10 10">
TextBlock Name="lblMsg" Margin="5" />
Image x:Name="imageProfile" Margin="5" Width="64" Height="64" HorizontalAlignment="Left" />
StackPanel>
Grid>
Page>
/*
* 演示如何获取用户的信息
*
* 需要在 Package.appxmanifest 中的“功能”中勾选“用户账户信息”,即
2、演示如何获取用户的同意
UserAndAccount/UserVerifier.xamlPage
x:Class="Windows10.UserAndAccount.UserVerifier"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.UserAndAccount"
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="10 0 10 10">
TextBlock Name="lblMsg" Margin="5" />
Button Name="buttonRequestConsent" Content="获取用户的同意" Click="buttonRequestConsent_Click" Margin="5" />
StackPanel>
Grid>
Page>
/*
* 演示如何获取用户的同意
*
* UserConsentVerifier - 验证器(比如 pin 验证等)
* CheckAvailabilityAsync() - 验证器的可用性
* RequestVerificationAsync(string message) - 请求用户的同意(可以指定用于提示用户的信息)
*/
using System;
using Windows.Security.Credentials.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace Windows10.UserAndAccount
{
public sealed partial class UserVerifier : Page
{
public UserVerifier()
{
this.InitializeComponent();
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
try
{
UserConsentVerifierAvailability verifierAvailability = await UserConsentVerifier.CheckAvailabilityAsync();
switch (verifierAvailability)
{
case UserConsentVerifierAvailability.Available: // 验证器可用
lblMsg.Text = "UserConsentVerifierAvailability.Available";
break;
case UserConsentVerifierAvailability.DeviceBusy:
lblMsg.Text = "UserConsentVerifierAvailability.DeviceBusy";
break;
case UserConsentVerifierAvailability.DeviceNotPresent:
lblMsg.Text = "UserConsentVerifierAvailability.DeviceNotPresent";
break;
case UserConsentVerifierAvailability.DisabledByPolicy:
lblMsg.Text = "UserConsentVerifierAvailability.DisabledByPolicy";
break;
case UserConsentVerifierAvailability.NotConfiguredForUser:
lblMsg.Text = "UserConsentVerifierAvailability.NotConfiguredForUser";
break;
default:
break;
}
}
catch (Exception ex)
{
lblMsg.Text = ex.ToString();
}
lblMsg.Text += "\n";
}
private async void buttonRequestConsent_Click(object sender, RoutedEventArgs e)
{
try
{
UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync("我要做一些操作,您同意吗?");
switch (consentResult)
{
case UserConsentVerificationResult.Verified: // 验证通过
lblMsg.Text += "UserConsentVerificationResult.Verified";
break;
case UserConsentVerificationResult.DeviceBusy:
lblMsg.Text += "UserConsentVerificationResult.DeviceBusy";
break;
case UserConsentVerificationResult.DeviceNotPresent:
lblMsg.Text += "UserConsentVerificationResult.DeviceNotPresent";
break;
case UserConsentVerificationResult.DisabledByPolicy:
lblMsg.Text += "UserConsentVerificationResult.DisabledByPolicy";
break;
case UserConsentVerificationResult.NotConfiguredForUser:
lblMsg.Text += "UserConsentVerificationResult.NotConfiguredForUser";
break;
case UserConsentVerificationResult.RetriesExhausted:
lblMsg.Text += "UserConsentVerificationResult.RetriesExhausted";
break;
case UserConsentVerificationResult.Canceled: // 验证取消
lblMsg.Text += "UserConsentVerificationResult.Canceled";
break;
default:
break;
}
}
catch (Exception ex)
{
lblMsg.Text += ex.ToString();
}
lblMsg.Text += "\n";
}
}
}
[源码下载]
文章标题:背水一战 Windows 10 (82) - 用户和账号: 获取用户的信息, 获取用户的同意
文章链接:http://soscw.com/index.php/essay/53449.html