コード例 #1
0
        protected ImageSourceState GetLoadedSource(bool invalidateLayout)
        {
            if (_loadImageSource)
            {
                DisposeImageSources();
                _fallbackSourceInUse = false;
                _loadImageSource     = false;
            }

            ImageSourceState allocatedSource = null;

            ImageSource imageSource = _sourceState.ImageSource;

            // Find a new image source
            if (imageSource == null)
            {
                imageSource        = _sourceState.ImageSource = LoadImageSource(Source, true);
                _sourceState.Setup = false;
            }

            if (imageSource != null && !imageSource.IsAllocated)
            {
                _sourceState.Setup = false;
                imageSource.Allocate();
            }

            if (imageSource != null && imageSource.IsAllocated)
            {
                allocatedSource = _sourceState;
            }
            else
            {
                ImageSource fallbackSource = _fallbackSourceState.ImageSource;
                // If the source image could not load yet, try fallback image
                if (fallbackSource == null)
                {
                    fallbackSource             = _fallbackSourceState.ImageSource = LoadImageSource(FallbackSource, false);
                    _fallbackSourceState.Setup = false;
                }

                if (fallbackSource != null && !fallbackSource.IsAllocated)
                {
                    _fallbackSourceState.Setup = false;
                    fallbackSource.Allocate();
                }

                if (fallbackSource != null && fallbackSource.IsAllocated)
                {
                    _fallbackSourceInUse = true;
                    allocatedSource      = _fallbackSourceState;
                }
            }

            if (invalidateLayout && allocatedSource != null && allocatedSource.ImageSource.SourceSize != _lastImageSourceSize)
            {
                InvalidateLayout(true, true);
            }
            HasImage = allocatedSource != null;

            return(allocatedSource);
        }