예제 #1
0
        static void ImageControlUnloaded(object sender, RoutedEventArgs e)
        {
            if (!(sender is Image imageControl))
            {
                return;
            }
            var source = GetAnimatedSource(imageControl);

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

            controller?.Dispose();
        }
예제 #2
0
        private static void AnimatedSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            if (!(o is Image imageControl))
            {
                return;
            }

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

            if (ReferenceEquals(oldValue, newValue))
            {
                if (imageControl.IsLoaded)
                {
                    var isAnimLoaded = GetIsAnimationLoaded(imageControl);
                    if (!isAnimLoaded)
                    {
                        InitAnimationOrImage(imageControl);
                    }
                }
                return;
            }
            if (oldValue != null)
            {
                imageControl.Loaded   -= ImageControlLoaded;
                imageControl.Unloaded -= ImageControlUnloaded;
                AnimationCache.DecrementReferenceCount(oldValue, GetRepeatBehavior(imageControl));
                var controller = GetAnimationController(imageControl);
                controller?.Dispose();
                imageControl.Source = null;
            }

            if (newValue == null)
            {
                return;
            }

            imageControl.Loaded   += ImageControlLoaded;
            imageControl.Unloaded += ImageControlUnloaded;
            if (imageControl.IsLoaded)
            {
                InitAnimationOrImage(imageControl);
            }
        }
예제 #3
0
        private static void RepeatBehaviorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            if (!(o is Image imageControl))
            {
                return;
            }

            var source = GetAnimatedSource(imageControl);

            if (source == null)
            {
                return;
            }

            if (!Equals(e.OldValue, e.NewValue))
            {
                AnimationCache.DecrementReferenceCount(source, (RepeatBehavior)e.OldValue);
            }
            if (imageControl.IsLoaded)
            {
                InitAnimationOrImage(imageControl);
            }
        }