private static void OnDisplayModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var             profileCard = d as ProfileCard;
            ProfileCardItem profileItem = profileCard.CurrentProfileItem.Clone();

            profileItem.DisplayMode        = (ViewType)e.NewValue;
            profileCard.CurrentProfileItem = profileItem;
        }
        private void InitUserProfile()
        {
            var profileItem = new ProfileCardItem()
            {
                UserPhoto         = DefaultImage ?? PersonPhoto,
                NormalMail        = NormalMailDefaultText ?? string.Empty,
                LargeProfileTitle = LargeProfileTitleDefaultText ?? string.Empty,
                LargeProfileMail  = LargeProfileMailDefaultText ?? string.Empty,
                DisplayMode       = DisplayMode
            };

            CurrentProfileItem = profileItem;
        }
        private async void FetchUserInfoAsync()
        {
            if (string.IsNullOrEmpty(UserId) || UserId.Equals("Invalid UserId"))
            {
                InitUserProfile();
            }
            else
            {
                MicrosoftGraphService graphService = MicrosoftGraphService.Instance;
                if (!(await graphService.TryLoginAsync()))
                {
                    return;
                }

                try
                {
                    var user        = await graphService.GraphProvider.Users[UserId].Request().GetAsync();
                    var profileItem = new ProfileCardItem()
                    {
                        NormalMail        = user.Mail,
                        LargeProfileTitle = user.DisplayName,
                        LargeProfileMail  = user.Mail,
                        DisplayMode       = DisplayMode
                    };

                    if (string.IsNullOrEmpty(user.Mail))
                    {
                        profileItem.UserPhoto = DefaultImage ?? PersonPhoto;
                    }
                    else
                    {
                        try
                        {
                            using (Stream photoStream = await graphService.GraphProvider.Users[UserId].Photo.Content.Request().GetAsync())
                                using (var ras = photoStream.AsRandomAccessStream())
                                {
                                    var bitmapImage = new BitmapImage();
                                    await bitmapImage.SetSourceAsync(ras);

                                    profileItem.UserPhoto = bitmapImage;
                                }
                        }
                        catch
                        {
                            // Swallow error in case of no photo found
                            profileItem.UserPhoto = DefaultImage ?? PersonPhoto;
                        }
                    }

                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        CurrentProfileItem = profileItem;
                    });
                }
                catch (ServiceException ex)
                {
                    // Swallow error in case of no user id found
                    if (!ex.Error.Code.Equals("Request_ResourceNotFound"))
                    {
                        throw;
                    }

                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        UserId = "Invalid UserId";
                    });
                }
            }
        }