[英]User Properties in UWP
除名字外,所有属性都返回空字符串。
我在代码中找不到任何错误。
我尝试了很多次,但仍然得到Empty字符串。 返回值的唯一属性是名字。
public static async void GetCurrenntLocalUsers
(ObservableCollection<UserInformation> informations )
{
IReadOnlyList<User> users = await
Windows.System.User.FindAllAsync(UserType.LocalUser,
UserAuthenticationStatus.LocallyAuthenticated);
foreach (var user in users)
{
IRandomAccessStreamReference img = await
user.GetPictureAsync(UserPictureSize.Size64x64);
var stream = await img.OpenReadAsync();
BitmapImage image=new BitmapImage();
image.SetSource(stream);
var userprop = await
user.GetPropertiesAsync(await getproperties());
string ff = userprop[KnownUserProperties.AccountName].ToString(); //Empty String
informations.Add(new UserInformation()
{
Name = userprop[KnownUserProperties.FirstName].ToString(),
DomainName = userprop[KnownUserProperties.DomainName].ToString(), //Empty String
UserImage = image
});
}
}
而getProperties是
private static async Task<IReadOnlyList<string>> getproperties()
{
var prop=new List<String>()
{
KnownUserProperties.FirstName,
KnownUserProperties.DomainName,
KnownUserProperties.AccountName
};
return prop;
}
参考应用功能
要访问Windows.System.UserProfile命名空间中的某些API,需要此userAccountInformation功能。 在应用的包清单中声明时,它必须包含uap命名空间,如下所示:
<Capabilities>
<uap:Capability Name="userAccountInformation" />
</Capabilities>
对于本地用户,只能通过User.GetPropertiesAsync()
方法实现DisplayName
属性。
对于域用户,以下属性等于实际值:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.