예제 #1
0
 void ImageLoadFail(object sender, ExceptionRoutedEventArgs e)
 {
     if (ImageFailed != null)
     {
         ImageFailed.Invoke(sender, e);
     }
 }
예제 #2
0
#pragma warning restore IDE1006 // Naming Styles

        protected override void OnApplyTemplate()
        {
            part_imageForeground              = (Image)GetTemplateChild(nameof(part_imageForeground));
            part_imageForeground.ImageOpened += (s, e) => ImageOpened?.Invoke(this, new RoutedEventArgs());
            part_imageBackground              = (Image)GetTemplateChild(nameof(part_imageBackground));
            part_imageBackground.ImageOpened += (s, e) => part_imageForeground.Source = part_imageBackground.Source;
            part_imageBackground.ImageFailed += (s, e) => ImageFailed?.Invoke(this, new RoutedEventArgs());
        }
예제 #3
0
파일: Image.cs 프로젝트: zzyzy/uno
        protected virtual void OnImageFailed(ImageSource imageSource)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().Debug(this.ToString() + " Image failed to open");
            }

            ImageFailed?.Invoke(this, new ExceptionRoutedEventArgs("Image failed to download"));
        }
예제 #4
0
        private void ImageLoadFail(object sender, ExceptionRoutedEventArgs e)
        {
            CleanupImageEvents(sender);

            if (ImageFailed != null)
            {
                ImageFailed.Invoke(sender, e);
            }
        }
예제 #5
0
파일: ImageBrush.cs 프로젝트: zzyzy/uno
        private void OnImageFailed()
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().Debug(ToString() + " Image failed to open");
            }

            ImageFailed?.Invoke(this, new ExceptionRoutedEventArgs("Image failed to open"));
        }
예제 #6
0
        private void image_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {
            ImageFailed?.Invoke(this, EventArgs.Empty);

            if (FallbackSource != null)
            {
                fallbackBrush.ImageSource = FallbackSource;
            }
        }
예제 #7
0
        protected override async void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            PART_Image              = GetTemplateChild(nameof(PART_Image)) as Image;
            PART_Image.ImageOpened += (object sender, RoutedEventArgs e) => ImageOpened?.Invoke(sender, e);
            PART_Image.ImageFailed += (object sender, ExceptionRoutedEventArgs e) => ImageFailed?.Invoke(sender, e);

            await SetImageSource(UriSource);
        }
예제 #8
0
        private async void SetSourceUri(Uri uri)
        {
            _currentUri = uri;
            try
            {
                if (uri.IsAbsoluteUri)
                {
                    var cachedUri = uri;
                    if (uri.Scheme == "http" || uri.Scheme == "https")
                    {
                        SetProgress();
                        _isHttpSource = true;
                        if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
                        {
                            cachedUri = await BitmapCache.GetImageUriAsync(uri, (int)_currentSize.Width, (int)_currentSize.Height);

                            if (cachedUri == null)
                            {
                                ClearProgress();
                                ClearImage();
                                ClearImageGif();

                                ImageFailed?.Invoke(this, new SourceEventArgs(uri.ToString()));
                                return;
                            }
                        }
                    }
                    if (Path.GetExtension(uri.LocalPath).Equals(".gif", StringComparison.OrdinalIgnoreCase))
                    {
                        this.SetImageGif(cachedUri);
                    }
                    else
                    {
                        this.SetImage(new BitmapImage(cachedUri));
                    }
                }
                else
                {
                    ClearImage();
                    ClearImageGif();
                }
            }
            catch
            {
                // Invalid Uri
                ClearImage();
                ClearImageGif();
            }
        }
예제 #9
0
        private async void SetSource(string source)
        {
            if (_image != null)
            {
                // 设计模式下直接显示。
                if (DesignMode.DesignModeEnabled)
                {
                    _image.Source = source == null ? null : new BitmapImage(new Uri(source, UriKind.RelativeOrAbsolute));
                }
                else
                {
                    if (source == null)
                    {
                        _image.Source = null;
                        VisualStateManager.GoToState(this, NormalStateName, true);
                    }
                    else
                    {
                        VisualStateManager.GoToState(this, LoadingStateName, true);
                        var result = await Loader.GetBitmapAsync(source);

                        if (source == Source)// 确保在执行异步操作过程中,Source 没有变动。
                        {
                            switch (result.Status)
                            {
                            case BitmapStatus.Opened:
                                _image.Source = result.Value;
                                VisualStateManager.GoToState(this, OpenedStateName, true);
                                ImageOpened?.Invoke(this, EventArgs.Empty);
                                break;

                            case BitmapStatus.Failed:
                                _image.Source = null;
                                VisualStateManager.GoToState(this, FailedStateName, true);
                                ImageFailed?.Invoke(this, new ImageFailedEventArgs(source, result.FailedException));
                                break;

                            default:
                                throw new ArgumentOutOfRangeException(nameof(result.Status));
                            }
                        }
                    }
                }
            }
        }
예제 #10
0
        private async void SetSource(string source)
        {
            var imageBrush = AssociatedObject;

            if (imageBrush != null)
            {
                // 设计模式下直接显示。
                if ((bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)
                {
                    imageBrush.ImageSource = source == null ? null : new BitmapImage(new Uri(source, UriKind.RelativeOrAbsolute));
                }
                else
                {
                    if (source == null)
                    {
                        imageBrush.ImageSource = null;
                    }
                    else
                    {
                        var result = await Loader.GetBitmapAsync(source);

                        if (source == Source) // 确保在执行异步操作过程中,Source 没有变动。
                        {
                            switch (result.Status)
                            {
                            case BitmapStatus.Opened:
                                imageBrush.ImageSource = result.Value;
                                ImageOpened?.Invoke(this, EventArgs.Empty);
                                break;

                            case BitmapStatus.Failed:
                                imageBrush.ImageSource = null;
                                ImageFailed?.Invoke(this, new ImageFailedEventArgs(source, result.FailedException));
                                break;

                            default:
                                throw new ArgumentOutOfRangeException(nameof(result.Status));
                            }
                        }
                    }
                }
            }
        }
예제 #11
0
 private void Holder_ImageFailed(object sender, ExceptionRoutedEventArgs e)
 {
     ImageFailed?.Invoke(this, e);
 }
예제 #12
0
 private void OnImageFailed(object sender, ExceptionRoutedEventArgs e)
 {
     ImageFailed?.Invoke(this, e);
     ImageExFailed?.Invoke(this, new ImageExFailedEventArgs(new Exception(e.ErrorMessage)));
     VisualStateManager.GoToState(this, FailedState, true);
 }
        private async Task SetDesignSourceAsync(object?source)
        {
            if (_image == null)
            {
                return;
            }

            _lastLoadCts?.Cancel();
            if (source == null)
            {
                AttachDesignSource(null);
                VisualStateManager.GoToState(this, EmptyStateName, true);
                return;
            }

            var loadCts = new CancellationTokenSource();

            _lastLoadCts = loadCts;
            try
            {
                IsLoading = true;

                VisualStateManager.GoToState(this, LoadingStateName, true);

                // 开始 Loading,重置 DownloadProgress
                DownloadProgress = default;

                var context = new LoadingContext <ImageSource>(_uiContext, source, AttachDesignSource, ActualWidth, ActualHeight);
                context.DownloadProgressChanged += (sender, progress) =>
                {
                    if (_uiContext != null)
                    {
                        _uiContext.Post(state =>
                        {
                            DownloadProgress = progress;
                        }, null);
                    }
                    else
                    {
                        DownloadProgress = progress;
                    }
                };

                var pipeDelegate = ImageExService.GetHandler <ImageSource>();
                var retryCount   = RetryCount;
                var retryDelay   = RetryDelay;
                var policy       = Policy.Handle <Exception>()
                                   .WaitAndRetryAsync(retryCount, count => retryDelay, (ex, delay) =>
                {
                    context.Reset();
                });
                await policy.ExecuteAsync(() => pipeDelegate.Invoke(context, loadCts.Token));

                if (!loadCts.IsCancellationRequested)
                {
                    VisualStateManager.GoToState(this, OpenedStateName, true);
                    if (_uiContext != null)
                    {
                        _uiContext.Post(state =>
                        {
                            ImageOpened?.Invoke(this, EventArgs.Empty);
                        }, null);
                    }
                    else
                    {
                        ImageOpened?.Invoke(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                if (!loadCts.IsCancellationRequested)
                {
                    AttachDesignSource(null);
                    VisualStateManager.GoToState(this, FailedStateName, true);
                    if (_uiContext != null)
                    {
                        _uiContext.Post(state =>
                        {
                            ImageFailed?.Invoke(this, new ImageExFailedEventArgs(source, ex));
                        }, null);
                    }
                    else
                    {
                        ImageFailed?.Invoke(this, new ImageExFailedEventArgs(source, ex));
                    }
                }
            }
            finally
            {
                if (!loadCts.IsCancellationRequested)
                {
                    IsLoading = false;
                }
            }
        }
예제 #14
0
 private void OnImageFailed(object sender, ExceptionRoutedEventArgs e)
 {
     ImageFailed?.Invoke(this, e);
     VisualStateManager.GoToState(this, "Failed", true);
 }
예제 #15
0
파일: BitmapImage.cs 프로젝트: jokm1/uno-2
 private void RaiseImageFailed(ExceptionRoutedEventArgs args)
 {
     ImageFailed?.Invoke(this, args);
 }