Windows 10 Settings
In Windows 10 the user must explicitly give permission to access the user information data. The first time it runs the application, Windows 10 privacy settings automatically prompt the message box, to confirm whether the application can read the user information or not.
Later at some point of time, ifthe user doesn't like the application accessing information, then he or she can disable it (go to settings -> Privacy -> Account -> select the application and disable,
Application Setting
Application must enable the User Account information in the Package.appxmanifest file, otherwise the application can’t access the user information.
Let us see a simple example of how to read user name and display account information.
Define the User Modal class,
- public class UniversalUserInfo: INotifyPropertyChanged
- {
- private string _userName;
- public string UserName
- {
- get
- {
- return _userName;
- }
- set
- {
- _userName = value;
- OnPropertyChanged(nameof(UserName));
- }
- }
-
- private BitmapImage _imgStream;
- publi BitmapImageImgStream
- {
- get
- {
- return _imgStream;
- }
- set
- {
- _imgStream = value;
- OnPropertyChanged(nameof(ImgStream));
- }
- }
- private string _userType;
-
- public string UserType
- {
- get
- {
- return _userType;
- }
- set
- {
- _userType = value;
- OnPropertyChanged(nameof(UserType));
- }
- }
-
- private string _authenticationStatus;
-
- public string AuthenticationStatus
- {
- get
- {
- return _authenticationStatus;
- }
- set
- {
- _authenticationStatus = value;
- OnPropertyChanged(nameof(AuthenticationStatus));
- }
- }
-
-
- public eventPropertyChangedEventHandlerPropertyChanged;
- protected virtual voidOnPropertyChanged(string propertyName = null)
- {
- PropertyChanged ? .Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
User class using to read the user information
User.FindAllAsync(); this function used to get all the user information and read each user's properties, such as name or picture name. Use the
KnowUserProperties to get all user properties.
There are wo ways we can pass this
KnowUserProperties -- single parameter passes or multiple properties
User.GetPropertyAsync() – returns single properties value
Ex: User.GetPropertyAsync(KnownUserProperties.AccountName);
User.GetPropertiesAsync passes the collection of properties and returns the collection of properties value
Ex:
- User.GetPropertiesAsync(newList < string > ()
- {
- KnownUserProperties.DisplayName,
- KnownUserProperties.DisplayName
- });
This article example uses the collection of the properties to get all the user information. The following function is used to prepare the collection of the Properties,
Read the picture information, call the GetPictureAsync function, and pass the size (Note: read the picture information it’s not under the KnownUserProperties).
User.GetPictureAsync(UserPictureSize.Size424x424);
And function return the IRandomAccessStreamReference to display to the GUI, and convert to the Bitmap image,
User AuthenticationStatus and UserType information are Enum types, the below function uses to convert the Enum to String,
Find Users () function to read the complete information and assign the UniversalUserInfo class,
Here's the output:
Find the complete
source code.