C# 如何在Windows应用商店应用程序中以PC用户名登录?
就像这条线一样 但是代码C# 如何在Windows应用商店应用程序中以PC用户名登录?,c#,windows-store-apps,C#,Windows Store Apps,就像这条线一样 但是代码 string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; 在Windows 8应用程序上似乎不起作用 我如何才能做到这一点?步骤1: 使用C和XAML语言创建空白的Windows应用商店应用程序 步骤2: x:Class="SetAccountPicture.UserProfileInformation" xmlns="http://schemas.m
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
在Windows 8应用程序上似乎不起作用
我如何才能做到这一点?步骤1:
使用C和XAML语言创建空白的Windows应用商店应用程序
步骤2:
x:Class="SetAccountPicture.UserProfileInformation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SetAccountPicture"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid Height="500" Width="1000">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button x:Name="Get_UserInformation" Click="Get_UserInformation_Click_1" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Height="60" Width="250" Content="Get User Information" FontSize="20"></Button>
<TextBlock Text="User's Display Name is: " Grid.Row="1" Grid.Column="0" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock Text="User First Name is: " Grid.Row="2" Grid.Column="0" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock Text="User Last Name is: " Grid.Row="3" Grid.Column="0" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock Text="Account Picture is: " Grid.Row="4" Grid.Column="0" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock x:Name="UserName" Text="User Name is: " Grid.Row="1" Grid.Column="1" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock x:Name="FistName" Text="First Name is: " Grid.Row="2" Grid.Column="1" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock x:Name="LastName" Text="Last Name is: " Grid.Row="3" Grid.Column="1" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<Image x:Name="AccountPicture" Height="150" Width="200" Grid.Row="4" Grid.Column="2" Stretch="Fill"></Image>
</Grid>
</Grid>
</Page>
步骤4:
string displayName = await UserInformation.GetDisplayNameAsync();
if (string.IsNullOrEmpty(displayName))
{
rootPage.NotifyUser("No Display Name was returned", NotifyType.StatusMessage);
}
else
{
UserName.Text = displayName;
}
获取当前用户的名字
注意:这仅适用于Microsoft帐户
string firstName = await UserInformation.GetFirstNameAsync();
if (string.IsNullOrEmpty(firstName))
{
rootPage.NotifyUser("No Display Name was returned", NotifyType.StatusMessage);
}
else
{
FistName.Text = firstName;
}
获取当前用户的姓氏;见:
string lastName = await UserInformation.GetLastNameAsync();
if (string.IsNullOrEmpty(lastName))
{
rootPage.NotifyUser("No Display Name was returned", NotifyType.StatusMessage);
}
else
{
LastName.Text = lastName;
}
获取当前用户的帐户图片
注意:您可以请求三种类型的图像。例如:小、大和视频动态图像。如果可用,它将返回
StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile;
if (image != null)
{
rootPage.NotifyUser("SmallImage path = " + image.Path, NotifyType.StatusMessage);
try
{
IRandomAccessStream imageStream = await image.OpenReadAsync();
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(imageStream);
AccountPicture.Source = bitmapImage;
}
catch (Exception ex)
{
rootPage.NotifyUser("Error opening stream: " + ex.ToString(), NotifyType.ErrorMessage);
}
}
else
{
rootPage.NotifyUser("Small Account Picture is not available", NotifyType.StatusMessage);
}
步骤1:
使用C和XAML语言创建空白的Windows应用商店应用程序
步骤2:
x:Class="SetAccountPicture.UserProfileInformation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SetAccountPicture"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid Height="500" Width="1000">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button x:Name="Get_UserInformation" Click="Get_UserInformation_Click_1" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Height="60" Width="250" Content="Get User Information" FontSize="20"></Button>
<TextBlock Text="User's Display Name is: " Grid.Row="1" Grid.Column="0" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock Text="User First Name is: " Grid.Row="2" Grid.Column="0" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock Text="User Last Name is: " Grid.Row="3" Grid.Column="0" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock Text="Account Picture is: " Grid.Row="4" Grid.Column="0" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock x:Name="UserName" Text="User Name is: " Grid.Row="1" Grid.Column="1" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock x:Name="FistName" Text="First Name is: " Grid.Row="2" Grid.Column="1" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock x:Name="LastName" Text="Last Name is: " Grid.Row="3" Grid.Column="1" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<Image x:Name="AccountPicture" Height="150" Width="200" Grid.Row="4" Grid.Column="2" Stretch="Fill"></Image>
</Grid>
</Grid>
</Page>
步骤4:
string displayName = await UserInformation.GetDisplayNameAsync();
if (string.IsNullOrEmpty(displayName))
{
rootPage.NotifyUser("No Display Name was returned", NotifyType.StatusMessage);
}
else
{
UserName.Text = displayName;
}
获取当前用户的名字
注意:这仅适用于Microsoft帐户
string firstName = await UserInformation.GetFirstNameAsync();
if (string.IsNullOrEmpty(firstName))
{
rootPage.NotifyUser("No Display Name was returned", NotifyType.StatusMessage);
}
else
{
FistName.Text = firstName;
}
获取当前用户的姓氏;见:
string lastName = await UserInformation.GetLastNameAsync();
if (string.IsNullOrEmpty(lastName))
{
rootPage.NotifyUser("No Display Name was returned", NotifyType.StatusMessage);
}
else
{
LastName.Text = lastName;
}
获取当前用户的帐户图片
注意:您可以请求三种类型的图像。例如:小、大和视频动态图像。如果可用,它将返回
StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile;
if (image != null)
{
rootPage.NotifyUser("SmallImage path = " + image.Path, NotifyType.StatusMessage);
try
{
IRandomAccessStream imageStream = await image.OpenReadAsync();
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(imageStream);
AccountPicture.Source = bitmapImage;
}
catch (Exception ex)
{
rootPage.NotifyUser("Error opening stream: " + ex.ToString(), NotifyType.ErrorMessage);
}
}
else
{
rootPage.NotifyUser("Small Account Picture is not available", NotifyType.StatusMessage);
}
阅读回答的问题。。谢谢你阅读这个问题的答案。。谢谢你,伙计