Exemplo n.º 1
0
        internal static Storyboard RotateFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as CompositeTransform) ?? new CompositeTransform();

            transform.Rotation = settings.Rotation;

            SetRenderTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.Rotation, 0, "(UIElement.RenderTransform).(CompositeTransform.Rotation)", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 2
0
        // ====================
        // SCALE
        // ====================

        internal static Storyboard ScaleXTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();
            var scale     = transform.Children[SCALE_INDEX] as ScaleTransform;

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, scale.ScaleX, settings.ScaleX,
                                   $"{GetTransformType(settings)}Transform.Children[{SCALE_INDEX}].ScaleX", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 3
0
        internal static Storyboard TranslateYTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var translate = transform.Children[TRANSLATE_INDEX] as TranslateTransform;

            SetTransform(element, settings, transform);

            element.ApplyAnimation(settings, translate.Y, settings.OffsetY.GetCalculatedOffset(element, OffsetTarget.Y),
                                   $"{GetTransformType(settings)}Transform.Children[{TRANSLATE_INDEX}].Y", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 4
0
        // ====================
        // ROTATE
        // ====================

        internal static Storyboard RotateTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();
            var rotate    = transform.Children[ROTATE_INDEX] as RotateTransform;

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, rotate.Angle, settings.Rotation,
                                   $"{(settings.TransformOn == TransformationType.Render ? "Render" : "Layout")}Transform.Children[{ROTATE_INDEX}].Angle", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 5
0
        // ====================
        // TRANSLATE
        // ====================

        internal static Storyboard TranslateXTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var translate = transform.Children[TRANSLATE_INDEX] as TranslateTransform;

            SetTransform(element, settings, transform);

            element.ApplyAnimation(settings, translate.X, settings.OffsetX.GetCalculatedOffset(element, OffsetTarget.X),
                                   $"{(settings.TransformOn == TransformationType.Render ? "Render" : "Layout")}Transform.Children[{TRANSLATE_INDEX}].X", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 6
0
        internal static Storyboard TranslateYFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as CompositeTransform) ?? new CompositeTransform();

            transform.TranslateY = settings.OffsetY.GetCalculatedOffset(element, OffsetTarget.Y);

            SetRenderTransform(element, settings, transform);

            element.ApplyAnimation(settings, transform.TranslateY, 0, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 7
0
        internal static Storyboard ScaleYTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();
            var scale     = transform.Children[SCALE_INDEX] as ScaleTransform;

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, scale.ScaleY, settings.ScaleY,
                                   $"{(settings.TransformOn == TransformationType.Render ? "Render" : "Layout")}Transform.Children[{SCALE_INDEX}].ScaleY", ref storyboard);

            return(storyboard);
        }
        internal static Storyboard TranslateYFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var translate = transform.Children[TRANSLATE_INDEX] as TranslateTransform;

            translate.Y = settings.OffsetY;

            SetRenderTransform(element, settings, transform);

            element.ApplyAnimation(settings, settings.OffsetY, 0, $"RenderTransform.Children[{TRANSLATE_INDEX}].Y", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 9
0
        internal static Storyboard TranslateXFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var translate = transform.Children[TRANSLATE_INDEX] as TranslateTransform;

            translate.X = settings.OffsetX.GetCalculatedOffset(element, OffsetTarget.X);

            SetRenderTransform(element, settings, transform);

            element.ApplyAnimation(settings, translate.X, 0, $"RenderTransform.Children[{TRANSLATE_INDEX}].X", ref storyboard);

            return(storyboard);
        }
        internal static Storyboard RotateFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var rotate    = transform.Children[ROTATE_INDEX] as RotateTransform;

            rotate.Angle = settings.Rotation;

            SetRenderTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.Rotation, 0, $"RenderTransform.Children[{ROTATE_INDEX}].Angle", ref storyboard);

            return(storyboard);
        }
        // ====================
        // FADE
        // ====================

        internal static Storyboard FadeTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            // Since a previous animation can have a "hold" on the Opacity property, we must "release" it before
            // setting a new value. See the Remarks section of the AttachedProperty for more info.
            if (Animations.GetAllowOpacityReset(element))
            {
                element.BeginAnimation(UIElement.OpacityProperty, null);
            }

            element.ApplyAnimation(settings, element.Opacity, settings.Opacity, "Opacity", ref storyboard);

            return(storyboard);
        }
        internal static Storyboard ScaleYFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = (element.RenderTransform as TransformGroup) ?? CreateTransformGroup();
            var scale     = transform.Children[SCALE_INDEX] as ScaleTransform;

            scale.ScaleY = settings.ScaleY;

            SetRenderTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.ScaleY, 1, $"RenderTransform.Children[{SCALE_INDEX}].ScaleY", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 13
0
        internal static Storyboard FadeFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            // TODO: Investigate to determine the use-case of having the need for calling BeginAnimation() in WPF

            // Since a previous animation can have a "hold" on the Opacity property, we must "release" it before setting a new value:
            // https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-set-a-property-after-animating-it-with-a-storyboard?view=netframework-4.7.2#remove-an-animation-from-an-individual-property
            //element.BeginAnimation(UIElement.OpacityProperty, null);

            element.Opacity = settings.Opacity;

            element.ApplyAnimation(settings, settings.Opacity, 1, "Opacity", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 14
0
        // ====================
        // COLOR
        // ====================

        internal static Storyboard ColorTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            Color fromColor    = Colors.Transparent;
            var   propertyPath = string.Empty;

            switch (settings.ColorOn)
            {
            case ColorTarget.Background when element is Control ctl && ctl.Background is SolidColorBrush brush:
                propertyPath = "(Control.Background).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.Foreground when element is Control ctl && ctl.Foreground is SolidColorBrush brush:
                propertyPath = "(Control.Foreground).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.BorderBrush when element is Control ctl && ctl.BorderBrush is SolidColorBrush brush:
                propertyPath = "(Control.BorderBrush).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.Foreground when element is TextBlock tb && tb.Foreground is SolidColorBrush brush:
                propertyPath = "(TextBlock.Foreground).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.Fill when element is Shape shp && shp.Fill is SolidColorBrush brush:
                propertyPath = "(Shape.Fill).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            case ColorTarget.Stroke when element is Shape shp && shp.Stroke is SolidColorBrush brush:
                propertyPath = "(Shape.Stroke).(SolidColorBrush.Color)";
                fromColor    = brush.Color;
                break;

            default:
                const string message =
                    "$Cannot animate the ColorAnimation. Make sure the animation is applied on a Control, TextBlock, or Shape. " +
                    "Also make sure that an existing brush exists on the corresponding property (Background, Foreground, BorderBrush, Fill, or Stroke).";
                throw new ArgumentException(message);
            }

            element.ApplyAnimation(settings, fromColor, settings.Color, propertyPath, ref storyboard);

            return(storyboard);
        }
Exemplo n.º 15
0
        internal static Storyboard RotateFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();

            transform.Children[ROTATE_INDEX] = new RotateTransform()
            {
                Angle = settings.Rotation
            };

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.Rotation, 0,
                                   $"{GetTransformType(settings)}Transform.Children[{ROTATE_INDEX}].Angle", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 16
0
        internal static Storyboard ScaleYFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var transform     = GetFrameworkElementTransform(element, settings) ?? CreateTransformGroup();
            var currentScaleX = (transform.Children[SCALE_INDEX] as ScaleTransform)?.ScaleX ?? 1;

            transform.Children[SCALE_INDEX] = new ScaleTransform()
            {
                ScaleX = currentScaleX,
                ScaleY = settings.ScaleY
            };

            SetTransform(element, settings, transform, updateTransformCenterPoint: true);

            element.ApplyAnimation(settings, settings.ScaleY, 1,
                                   $"{GetTransformType(settings)}Transform.Children[{SCALE_INDEX}].ScaleY", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 17
0
        // ====================
        // FADE
        // ====================

        internal static Storyboard FadeTo(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            element.ApplyAnimation(settings, element.Opacity, settings.Opacity, "(UIElement.Opacity)", ref storyboard);

            return(storyboard);
        }
Exemplo n.º 18
0
        internal static Storyboard ColorFrom(this FrameworkElement element, AnimationSettings settings, ref Storyboard storyboard)
        {
            var          toColor      = Colors.Transparent;
            var          propertyPath = string.Empty;
            var          type         = element.GetType();
            var          elementType  = $"{type.Namespace}:{type.Name}";
            const string brushTarget  = "Windows.UI.Xaml.Media:SolidColorBrush.Color";

            switch (settings.ColorOn)
            {
#if HAS_UNO
            case ColorTarget.Background when element is FrameworkElement elem:
                propertyPath    = $"({elementType}.Background).({brushTarget})";
                toColor         = (elem.Background as SolidColorBrush)?.Color ?? Colors.Transparent;
                elem.Background = new SolidColorBrush(settings.Color);
                break;
#else
            case ColorTarget.Background when element is Control ctl:
                propertyPath   = $"({elementType}.Background).({brushTarget})";
                toColor        = (ctl.Background as SolidColorBrush)?.Color ?? Colors.Transparent;
                ctl.Background = new SolidColorBrush(settings.Color);
                break;
#endif
            case ColorTarget.Background when element is Panel pnl:
                propertyPath   = $"({elementType}.Background).({brushTarget})";
                toColor        = (pnl.Background as SolidColorBrush)?.Color ?? Colors.Transparent;
                pnl.Background = new SolidColorBrush(settings.Color);
                break;

            case ColorTarget.Foreground when element is Control ctl:
                propertyPath   = $"({elementType}.Foreground).({brushTarget})";
                toColor        = (ctl.Foreground as SolidColorBrush)?.Color ?? Colors.Transparent;
                ctl.Foreground = new SolidColorBrush(settings.Color);
                break;

            case ColorTarget.BorderBrush when element is Control ctl:
                propertyPath    = $"({elementType}.BorderBrush).({brushTarget})";
                toColor         = (ctl.BorderBrush as SolidColorBrush)?.Color ?? Colors.Transparent;
                ctl.BorderBrush = new SolidColorBrush(settings.Color);
                break;

            case ColorTarget.Foreground when element is TextBlock tb:
                propertyPath  = $"({elementType}.Foreground).({brushTarget})";
                toColor       = (tb.Foreground as SolidColorBrush)?.Color ?? Colors.Transparent;
                tb.Foreground = new SolidColorBrush(settings.Color);
                break;

            case ColorTarget.Fill when element is Shape shp:
                propertyPath = $"({elementType}.Fill).({brushTarget})";
                toColor      = (shp.Fill as SolidColorBrush)?.Color ?? Colors.Transparent;
                shp.Fill     = new SolidColorBrush(settings.Color);
                break;

            case ColorTarget.Stroke when element is Shape shp:
                propertyPath = $"({elementType}.Stroke).({brushTarget})";
                toColor      = (shp.Stroke as SolidColorBrush)?.Color ?? Colors.Transparent;
                shp.Stroke   = new SolidColorBrush(settings.Color);
                break;

            default:
                const string message =
                    "$Cannot animate the ColorAnimation. Make sure the animation is applied on a Control, TextBlock, or Shape. " +
                    "Also make sure that an existing brush exists on the corresponding property (Background, Foreground, BorderBrush, Fill, or Stroke).";
                throw new ArgumentException(message);
            }

            element.ApplyAnimation(settings, settings.Color, toColor, propertyPath, ref storyboard);

            return(storyboard);
        }