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(); } }
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 (ReferenceEquals(oldValue, newValue)) { return; } 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); } } }
private static void RepeatBehaviorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { Image imageControl = o as Image; if (imageControl == null) { return; } ImageSource source = GetAnimatedSource(imageControl); if (source != null) { if (!Equals(e.OldValue, e.NewValue)) { AnimationCache.DecrementReferenceCount(source, (RepeatBehavior)e.OldValue); } if (imageControl.IsLoaded) { InitAnimationOrImage(imageControl); } } }