private static void AnimatedSourceChanged( DependencyObject o, DependencyPropertyChangedEventArgs e) { if (!(o is Image imageControl)) { return; } ImageSource oldValue = e.OldValue as ImageSource; ImageSource newValue = e.NewValue as ImageSource; if (oldValue == newValue) { return; } if (oldValue != null) { imageControl.Loaded -= new RoutedEventHandler(ImageBehavior.ImageControlLoaded); imageControl.Unloaded -= new RoutedEventHandler(ImageBehavior.ImageControlUnloaded); AnimationCache.DecrementReferenceCount(oldValue, ImageBehavior.GetRepeatBehavior(imageControl)); ImageBehavior.GetAnimationController(imageControl)?.Dispose(); imageControl.Source = (ImageSource)null; } if (newValue == null) { return; } imageControl.Loaded += new RoutedEventHandler(ImageBehavior.ImageControlLoaded); imageControl.Unloaded += new RoutedEventHandler(ImageBehavior.ImageControlUnloaded); if (!imageControl.IsLoaded) { return; } ImageBehavior.InitAnimationOrImage(imageControl); }
private static void ImageControlLoaded(object sender, RoutedEventArgs e) { if (!(sender is Image imageControl)) { return; } ImageBehavior.InitAnimationOrImage(imageControl); }
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)); }
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); } }
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); }