internal static IAnimationSettings GetSettings(
            this FrameworkElement element,
            SettingsTarget target,
            Func <FrameworkElement, IAnimationSettings> getPrimaryFunc   = null,
            Func <FrameworkElement, IAnimationSettings> getSecondaryFunc = null,
            Func <FrameworkElement, AnimationSettings> getStartWithFunc  = null)
        {
            IAnimationSettings settings = null;

            switch (target)
            {
            case SettingsTarget.Primary:
                settings = getPrimaryFunc(element);
                break;

            case SettingsTarget.Secondary:
                settings = getSecondaryFunc(element);
                break;

            case SettingsTarget.StartWith:
                settings = getStartWithFunc(element);
                break;
            }

            // Settings can be null if a Trigger is set before the associated element is loaded
            if (settings == null)
            {
                return(null);
            }

            return(settings);
        }
Example #2
0
        private AnimationSettingViewModel CreateAnimationSettingViewModel(IAnimationSettings settings, BitmapRepository bitmapRepository)
        {
            if (settings is BitmapAnimationSettings bitmapAnimation)
            {
                foreach (BitmapAnimationSettingsViewModel viewmodel in AnimationSettings.OfType <BitmapAnimationSettingsViewModel>().Where(x => x.BitmapName == bitmapAnimation.ImageName))
                {
                    // Use this image for mem efficiency
                    return(new BitmapAnimationSettingsViewModel(bitmapAnimation, viewmodel.Bitmap));
                }

                return(new BitmapAnimationSettingsViewModel(bitmapAnimation, bitmapRepository));
            }
            if (settings is MovingPatternAnimationSettings movingPatternSetting)
            {
                return(new MovingPatternAnimationSettingsViewModel(movingPatternSetting));
            }
            if (settings is SlidingPatternAnimationSettings slidingPatternSetting)
            {
                return(new SlidingPatternAnimationSettingsViewModel(slidingPatternSetting));
            }
            if (settings is RepeatingPatternAnimationSettings repeatingPatternSetting)
            {
                return(new RepeatingPatternsAnimationSettingsViewModel(repeatingPatternSetting));
            }
            if (settings is RandomFadeAnimationSettings randomFadeSetting)
            {
                return(new RandomFadeAnimationSettingsViewModel(randomFadeSetting));
            }
            if (settings is FadingPulseAnimationSettings fadingPulseSetting)
            {
                return(new FadingPulseAnimationSettingsViewModel(fadingPulseSetting));
            }

            throw new NotImplementedException();
        }
Example #3
0
        internal static List <AnimationSettings> ToSettingsList(this IAnimationSettings settings)
        {
            var animations = new List <AnimationSettings>();

            if (settings is CompoundSettings compound)
            {
                animations.AddRange(compound.Sequence);
            }
            else if (settings is AnimationSettings anim)
            {
                animations.Add(anim);
            }

            return(animations);
        }
Example #4
0
        private static void RegisterElementEvents(FrameworkElement element, IAnimationSettings settings, bool useSecondarySettings = false)
        {
            var eventName = settings?.Event ?? nameof(FrameworkElement.Loaded);

            if (eventName.Equals(AnimationSettings.None, StringComparison.OrdinalIgnoreCase))
            {
                // Do nothing for "None"
            }
            else if (eventName.Equals(nameof(FrameworkElement.Visibility), StringComparison.OrdinalIgnoreCase))
            {
                element
                .Observe(FrameworkElement.VisibilityProperty)
                .Where(_ => element.Visibility == Visibility.Visible)
                .TakeUntil(element.Events().Unloaded)
                .Subscribe(
                    _ => PrepareAnimations(element, useSecondaryAnimation: useSecondarySettings),
                    ex => Logger?.LogError($"Error on subscription to the {nameof(FrameworkElement.Visibility)} changes of {nameof(FrameworkElement)}", ex),
                    () => Cleanup(element)
                    );
            }
            else if (eventName.Equals(nameof(FrameworkElement.DataContextChanged), StringComparison.OrdinalIgnoreCase))
            {
                element
                .Events()
                .DataContextChanged
                .DistinctUntilChanged(args => args.EventArgs.NewValue)
                .TakeUntil(element.Events().Unloaded)
                .Subscribe(
                    args => PrepareAnimations(args.Sender as FrameworkElement, useSecondaryAnimation: useSecondarySettings),
                    ex => Logger?.LogError($"Error on subscription to the {nameof(FrameworkElement.DataContextChanged)} event.", ex),
                    () => Cleanup(element)
                    );
            }
            else
            {
                Observable.FromEventPattern(element, eventName)
                .TakeUntil(element.Events().Unloaded)
                .Subscribe(
                    args => PrepareAnimations(args.Sender as FrameworkElement, useSecondaryAnimation: useSecondarySettings),
                    ex => Logger?.LogError($"Error on subscription to the {eventName} event.", ex),
                    () => Cleanup(element));
            }
        }
Example #5
0
        private static void RegisterElementEvents(FrameworkElement element, IAnimationSettings settings, bool useSecondarySettings = false)
        {
            switch (settings?.Event ?? AnimationSettings.DEFAULT_EVENT)
            {
            case EventType.Loaded:
            {
                element
                .Events()
                .LoadedUntilUnloaded
                .Subscribe(
                    args => PrepareAnimations(args.Sender as FrameworkElement, useSecondaryAnimation: useSecondarySettings),
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.Loaded)} event of {nameof(FrameworkElement)}", ex),
                    () => Cleanup(element)
                    );

                break;
            }

            case EventType.Visibility:
            {
                element
                .Observe(FrameworkElement.VisibilityProperty)
                .Where(_ => element.Visibility == Visibility.Visible)
                .TakeUntil(element.Events().UnloadedMaterialized)
                .Subscribe(
                    _ => PrepareAnimations(element, useSecondaryAnimation: useSecondarySettings),
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.Visibility)} changes of {nameof(FrameworkElement)}", ex),
                    () => Cleanup(element)
                    );

                break;
            }

            case EventType.DataContextChanged:
            {
                element
                .Events()
                .DataContextChanged
                .TakeUntil(element.Events().UnloadedMaterialized)
                .Subscribe(
                    args => PrepareAnimations(args.Sender as FrameworkElement, useSecondaryAnimation: useSecondarySettings),
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.DataContextChanged)} event of {nameof(FrameworkElement)}", ex),
                    () => Cleanup(element)
                    );

                break;
            }

            case EventType.PointerOver:
            {
                element
                .Events()
                .PointerEntered
                .TakeUntil(element.Events().UnloadedMaterialized)
                .Subscribe(
                    args => PrepareAnimations(args.Sender as FrameworkElement, useSecondaryAnimation: useSecondarySettings),
#if __WPF__
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.MouseEnter)} event of {nameof(FrameworkElement)}", ex),
#else
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.PointerEntered)} event of {nameof(FrameworkElement)}", ex),
#endif
                    () => Cleanup(element)
                    );

                break;
            }

            case EventType.PointerExit:
            {
                element
                .Events()
                .PointerExited
                .TakeUntil(element.Events().UnloadedMaterialized)
                .Subscribe(
                    args => PrepareAnimations(args.Sender as FrameworkElement, useSecondaryAnimation: useSecondarySettings),
#if __WPF__
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.MouseLeave)} event of {nameof(FrameworkElement)}", ex),
#else
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.PointerExited)} event of {nameof(FrameworkElement)}", ex),
#endif
                    () => Cleanup(element)
                    );

                break;
            }

            case EventType.GotFocus:
            {
                element
                .Events()
                .GotFocus
                .TakeUntil(element.Events().UnloadedMaterialized)
                .Subscribe(
                    args => PrepareAnimations(args.Sender as FrameworkElement, useSecondaryAnimation: useSecondarySettings),
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.GotFocus)} event of {nameof(FrameworkElement)}", ex),
                    () => Cleanup(element)
                    );

                break;
            }

            case EventType.LostFocus:
            {
                element
                .Events()
                .LostFocus
                .TakeUntil(element.Events().UnloadedMaterialized)
                .Subscribe(
                    args => PrepareAnimations(args.Sender as FrameworkElement, useSecondaryAnimation: useSecondarySettings),
                    ex => Logger.ErrorException($"Error on subscription to the {nameof(FrameworkElement.LostFocus)} event of {nameof(FrameworkElement)}", ex),
                    () => Cleanup(element)
                    );

                break;
            }
            }
        }
 public static void SetSecondary(DependencyObject obj, IAnimationSettings value) => obj.SetValue(SecondaryProperty, value);
 public AnimationSettingViewModel(IAnimationSettings animationSettings)
 {
     StartIndex    = animationSettings.StartIndex;
     StripLength   = animationSettings.StripLength;
     RelativeStart = animationSettings.RelativeStart;
 }