Beispiel #1
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));
        }
Beispiel #2
0
 private static void SetAnimationController(DependencyObject obj, ImageAnimationController value)
 {
     obj?.SetValue(ImageBehavior.AnimationControllerPropertyKey, (object)value);
 }