Esempio n. 1
0
        private static void AnimatedSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            Image imageControl = o as Image;

            if (imageControl == null)
            {
                return;
            }

            var oldValue = e.OldValue as ImageSource;
            var newValue = e.NewValue as ImageSource;

            if (oldValue != null)
            {
                imageControl.Loaded   -= ImageControlLoaded;
                imageControl.Unloaded -= ImageControlUnloaded;
                AnimationCache.DecrementReferenceCount(oldValue, GetRepeatBehavior(imageControl));
                var controller = GetAnimationController(imageControl);
                if (controller != null)
                {
                    controller.Dispose();
                }
                imageControl.Source = null;
            }
            if (newValue != null)
            {
                imageControl.Loaded   += ImageControlLoaded;
                imageControl.Unloaded += ImageControlUnloaded;
                if (imageControl.IsLoaded)
                {
                    InitAnimationOrImage(imageControl);
                }
            }
        }
Esempio n. 2
0
        private static void AnimatedSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            Image image = o as Image;

            if (image != null)
            {
                ImageSource oldValue = e.OldValue as ImageSource;
                ImageSource newValue = e.NewValue as ImageSource;
                if (oldValue != null)
                {
                    image.Loaded   -= new RoutedEventHandler(ImageBehavior.ImageControlLoaded);
                    image.Unloaded -= new RoutedEventHandler(ImageBehavior.ImageControlUnloaded);
                    AnimationCache.DecrementReferenceCount(oldValue, GetRepeatBehavior(image));
                    ImageAnimationController animationController = GetAnimationController(image);
                    if (animationController != null)
                    {
                        animationController.Dispose();
                    }
                    image.Source = null;
                }
                if (newValue != null)
                {
                    image.Loaded   += new RoutedEventHandler(ImageBehavior.ImageControlLoaded);
                    image.Unloaded += new RoutedEventHandler(ImageBehavior.ImageControlUnloaded);
                    if (image.IsLoaded)
                    {
                        InitAnimationOrImage(image);
                    }
                }
            }
        }
Esempio n. 3
0
        private static void ImageControlUnloaded(object sender, RoutedEventArgs e)
        {
            Image image = sender as Image;

            if (image != null)
            {
                ImageSource animatedSource = GetAnimatedSource(image);
                if (animatedSource != null)
                {
                    AnimationCache.DecrementReferenceCount(animatedSource, GetRepeatBehavior(image));
                }
                ImageAnimationController animationController = GetAnimationController(image);
                if (animationController != null)
                {
                    animationController.Dispose();
                }
            }
        }
Esempio n. 4
0
        private static void RepeatBehaviorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            Image image = o as Image;

            if (image != null)
            {
                ImageSource animatedSource = GetAnimatedSource(image);
                if (animatedSource != null)
                {
                    if (!Equals(e.OldValue, e.NewValue))
                    {
                        AnimationCache.DecrementReferenceCount(animatedSource, (RepeatBehavior)e.OldValue);
                    }
                    if (image.IsLoaded)
                    {
                        InitAnimationOrImage(image);
                    }
                }
            }
        }
Esempio n. 5
0
        static void ImageControlUnloaded(object sender, RoutedEventArgs e)
        {
            Image imageControl = sender as Image;

            if (imageControl == null)
            {
                return;
            }
            var source = GetAnimatedSource(imageControl);

            if (source != null)
            {
                AnimationCache.DecrementReferenceCount(source, GetRepeatBehavior(imageControl));
            }
            var controller = GetAnimationController(imageControl);

            if (controller != null)
            {
                controller.Dispose();
            }
        }