Exemplo n.º 1
0
        private void OnImageOpened()
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().Debug(ToString() + " Image opened successfully");
            }

            ImageOpened?.Invoke(this, new RoutedEventArgs(this));
        }
Exemplo n.º 2
0
Arquivo: Image.cs Projeto: zzyzy/uno
        protected virtual void OnImageOpened(ImageSource imageSource)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().Debug(this.ToString() + " Image opened successfully");
            }

            ImageOpened?.Invoke(this, RoutedEventArgs.Empty);
            _successfullyOpenedImage = imageSource;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Bitmap Opened
        /// </summary>
        /// <param name="source"></param>

        private void BitmapOpened(BitmapSource source)
        {
            this.PixelWidth = source.PixelWidth;
            this.PixelHeight = source.PixelHeight;

            var pixelPanel = this.ItemsPanelRoot as PixelPanel;

            if (pixelPanel != null)
            {
                pixelPanel.SetPixelSize(source.PixelWidth, source.PixelHeight);
            }

            ImageOpened?.Invoke(this, new RoutedEventArgs());
        }
Exemplo n.º 5
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));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
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));
                            }
                        }
                    }
                }
            }
        }
        private void ImageControlOnImageOpened(object sender, RoutedEventArgs routedEventArgs)
        {
            ImageOpened?.Invoke(this, routedEventArgs);

            var visual = ElementCompositionPreview.GetElementVisual((UIElement)sender);

            visual.Scale   = new Vector3(0.9f, 0.9f, 1);
            visual.Opacity = 0;

            visual.CenterPoint = new Vector3((float)ImageControl.ActualWidth / 2, (float)ImageControl.ActualHeight / 2,
                                             0);

            var visualImplicitAnimations = _compositor.CreateImplicitAnimationCollection();
            var animation = _compositor.CreateVector3KeyFrameAnimation();

            animation.Target = nameof(Visual.Scale);
            animation.InsertExpressionKeyFrame(1.0f, "this.FinalValue");
            animation.Duration = TimeSpan.FromMilliseconds(AnimationDuration);
            visualImplicitAnimations[nameof(Visual.Scale)] = animation;
            visual.ImplicitAnimations = visualImplicitAnimations;

            var insetClip = _compositor.CreateInsetClip(0, 0, 0, 0);

            visual.Clip = insetClip;

            var opacityAnimation = _compositor.CreateScalarKeyFrameAnimation(
                nameof(Visual.Opacity),
                0.0f,
                1.0f,
                TimeSpan.FromMilliseconds(500));

            visual.StartAnimation(nameof(Visual.Opacity), opacityAnimation);
            visual.Scale = new Vector3(1, 1, 1);

            var detailVisual = ElementCompositionPreview.GetElementVisual(DetailPanel);

            detailVisual.Opacity = 0;
            var finalOffset = new Vector3(0, (float)RootVisual.ActualHeight, 0);

            detailVisual.Offset = finalOffset;

            _isLoaded = true;
        }
 private void Holder_ImageOpened(object sender, RoutedEventArgs e)
 {
     ImageOpened?.Invoke(this, e);
 }
Exemplo n.º 9
0
 private void OnImageOpened(object sender, RoutedEventArgs e)
 {
     ImageOpened?.Invoke(this, e);
     ImageExOpened?.Invoke(this, new ImageExOpenedEventArgs());
     VisualStateManager.GoToState(this, LoadedState, true);
 }
Exemplo n.º 10
0
 private void Image_ImageOpened(object sender, RoutedEventArgs e)
 {
     ImageOpened?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 11
0
        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;
                }
            }
        }
Exemplo n.º 12
0
 private void RaiseImageOpened(RoutedEventArgs args)
 {
     ImageOpened?.Invoke(this, args);
 }