簡體   English   中英

UWP中的用戶屬性

[英]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屬性。

對於域用戶,以下屬性等於實際值:

  • 顯示名稱:陳富蘭
  • 域名:xxxx.domain.COM \\ user_alias
  • 名:富蘭克林
  • 姓:陳
  • SessionInitiationProtocolUri:sip://user_alias@domain.com

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM