Ejemplo n.º 1
0
        private static void ImageControlUnloaded(object sender, RoutedEventArgs e)
        {
            if (!(sender is Image imageControl))
            {
                return;
            }
            ImageSource animatedSource = ImageBehavior.GetAnimatedSource(imageControl);

            if (animatedSource != null)
            {
                AnimationCache.DecrementReferenceCount(animatedSource, ImageBehavior.GetRepeatBehavior(imageControl));
            }
            ImageBehavior.GetAnimationController(imageControl)?.Dispose();
        }
Ejemplo n.º 2
0
        private static void InitAnimationOrImage(Image imageControl)
        {
            ImageBehavior.SetAnimationController((DependencyObject)imageControl, (ImageAnimationController)null);
            ImageBehavior.SetIsAnimationLoaded(imageControl, false);
            BitmapSource source = ImageBehavior.GetAnimatedSource(imageControl) as BitmapSource;
            bool         flag1  = (DesignerProperties.GetIsInDesignMode((DependencyObject)imageControl) ? 1 : 0) == 0 | ImageBehavior.GetAnimateInDesignMode((DependencyObject)imageControl);
            bool         flag2  = ImageBehavior.IsLoadingDeferred(source);

            if (source != null & flag1 && !flag2)
            {
                if (source.IsDownloading)
                {
                    EventHandler handler = (EventHandler)null;
                    handler = (EventHandler)((sender, args) =>
                    {
                        source.DownloadCompleted -= handler;
                        ImageBehavior.InitAnimationOrImage(imageControl);
                    });
                    source.DownloadCompleted += handler;
                    imageControl.Source       = (ImageSource)source;
                    return;
                }
                ObjectAnimationUsingKeyFrames animation = ImageBehavior.GetAnimation(imageControl, source);
                if (animation != null)
                {
                    if (animation.KeyFrames.Count > 0)
                    {
                        ImageBehavior.TryTwice((System.Action)(() => imageControl.Source = (ImageSource)animation.KeyFrames[0].Value));
                    }
                    else
                    {
                        imageControl.Source = (ImageSource)source;
                    }
                    ImageAnimationController animationController = new ImageAnimationController(imageControl, animation, ImageBehavior.GetAutoStart(imageControl));
                    ImageBehavior.SetAnimationController((DependencyObject)imageControl, animationController);
                    ImageBehavior.SetIsAnimationLoaded(imageControl, true);
                    imageControl.RaiseEvent(new RoutedEventArgs(ImageBehavior.AnimationLoadedEvent, (object)imageControl));
                    return;
                }
            }
            imageControl.Source = (ImageSource)source;
            if (source == null)
            {
                return;
            }
            ImageBehavior.SetIsAnimationLoaded(imageControl, true);
            imageControl.RaiseEvent(new RoutedEventArgs(ImageBehavior.AnimationLoadedEvent, (object)imageControl));
        }
Ejemplo n.º 3
0
        private static void AnimateInDesignModeChanged(
            DependencyObject o,
            DependencyPropertyChangedEventArgs e)
        {
            if (!(o is Image imageControl))
            {
                return;
            }
            bool newValue = (bool)e.NewValue;

            if (ImageBehavior.GetAnimatedSource(imageControl) == null || !imageControl.IsLoaded)
            {
                return;
            }
            if (newValue)
            {
                ImageBehavior.InitAnimationOrImage(imageControl);
            }
            else
            {
                imageControl.BeginAnimation(Image.SourceProperty, (AnimationTimeline)null);
            }
        }
Ejemplo n.º 4
0
        private static void RepeatBehaviorChanged(
            DependencyObject o,
            DependencyPropertyChangedEventArgs e)
        {
            if (!(o is Image imageControl))
            {
                return;
            }
            ImageSource animatedSource = ImageBehavior.GetAnimatedSource(imageControl);

            if (animatedSource == null)
            {
                return;
            }
            if (!object.Equals(e.OldValue, e.NewValue))
            {
                AnimationCache.DecrementReferenceCount(animatedSource, (RepeatBehavior)e.OldValue);
            }
            if (!imageControl.IsLoaded)
            {
                return;
            }
            ImageBehavior.InitAnimationOrImage(imageControl);
        }