Exemple #1
0
        void OnDisplayNameChanged(DependencyPropertyChangedEventArgs args)
        {
            m_displayNameInitials = InitialsGenerator.InitialsFromDisplayName(DisplayName);

            UpdateIfReady();
        }
Exemple #2
0
        void UpdateControlForContact(bool isNewContact)
        {
            Contact contact = Contact;

            if (contact == null)
            {
                // Explicitly setting to empty/null ensures the bound XAML is
                // correctly updated.
                m_contactDisplayNameInitials = "";
                m_contactImageSource         = null;
                UpdateIfReady();
                return;
            }

            // It's possible for a second update to occur before the first finished loading
            // a profile picture (regardless of second having a picture or not).
            // Cancellation of any previously-activated tasks will mitigate race conditions.
            if (m_profilePictureReadAsync != null)
            {
                m_profilePictureReadAsync.Cancel();
            }

            m_contactDisplayNameInitials = InitialsGenerator.InitialsFromContactObject(contact);

            // Order of preference (but all work): Large, Small, Source, Thumbnail
            IRandomAccessStreamReference thumbStreamReference = null;

            if (PreferSmallImage && contact.SmallDisplayPicture != null)
            {
                thumbStreamReference = contact.SmallDisplayPicture;
            }
            else
            {
                if (contact.LargeDisplayPicture != null)
                {
                    thumbStreamReference = contact.LargeDisplayPicture;
                }
                else if (contact.SmallDisplayPicture != null)
                {
                    thumbStreamReference = contact.SmallDisplayPicture;
                }
                else if (contact.SourceDisplayPicture != null)
                {
                    thumbStreamReference = contact.SourceDisplayPicture;
                }
                else if (contact.Thumbnail != null)
                {
                    thumbStreamReference = contact.Thumbnail;
                }
            }

            // If we have profile picture data available per the above, async load the picture from the platform.
            if (thumbStreamReference != null)
            {
                if (isNewContact)
                {
                    // Prevent the case where context of a contact changes, but we show an old person while the new one is loaded.
                    m_contactImageSource = null;
                }

                // The dispatcher is not available in design mode, so when in design mode bypass the call to LoadImageAsync.
                if (!SharedHelpers.IsInDesignMode())
                {
                    // Contact is not yet supported
                    throw new NotSupportedException("Contact is not yet supported");

                    //LoadImageAsync(
                    //	thumbStreamReference,
                    //	[strongThis](BitmapImage profileBitmap)
                    //{
                    //	profileBitmap.DecodePixelType(DecodePixelType.Logical);

                    //	// We want to constrain the shorter side to the same dimension as the control, allowing the decoder to
                    //	// choose the other dimension without distorting the image.
                    //	if (profileBitmap.PixelHeight() < profileBitmap.PixelWidth())
                    //	{
                    //		profileBitmap.DecodePixelHeight((int)(strongThis.Height()));
                    //	}
                    //	else
                    //	{
                    //		profileBitmap.DecodePixelWidth((int)(strongThis.Width()));
                    //	}

                    //	strongThis.m_contactImageSource = ImageSource(profileBitmap));
                    //	strongThis.UpdateIfReady();
                    //});
                }
            }
            else
            {
                // Else clause indicates that (Contact.Thumbnail == null).
                m_contactImageSource = null;
            }

            UpdateIfReady();
        }