public static void UpdateBrush(UIElement uiElement)
        {
            RevealBrushState revealBrushState = RevealBrushHelper.GetState(uiElement);
            RevealBrushMode  revealBrushMode  = RevealBrushHelper.GetRevealBrushMode(uiElement);

            if (RevealBrushHelper.GetRevealBrush(uiElement) is RadialGradientBrush brush)
            {
                if (revealBrushMode == RevealBrushMode.Background)
                {
                    brush.Opacity = (revealBrushState != RevealBrushState.Normal) ? 0.1 : 0.0;
                }
                else if (revealBrushMode == RevealBrushMode.BackgroundPressed)
                {
                    if (revealBrushState == RevealBrushState.Pressed)
                    {
                        var time           = TimeSpan.FromMilliseconds(1500);
                        var easingFunction = new CubicEase()
                        {
                            EasingMode = EasingMode.EaseOut
                        };

                        var opacityAnimation = new DoubleAnimation(1.0, 0.0, time)
                        {
                            EasingFunction = easingFunction
                        };

                        brush.BeginAnimation(Brush.OpacityProperty, opacityAnimation);

                        var radiusAnimation = new DoubleAnimation(50.0, 200.0, time)
                        {
                            EasingFunction = easingFunction
                        };

                        brush.BeginAnimation(RadialGradientBrush.RadiusXProperty, radiusAnimation);
                        brush.BeginAnimation(RadialGradientBrush.RadiusYProperty, radiusAnimation);

                        var gradientStop = brush.GradientStops[1];

                        var offsetAnimation = new DoubleAnimation(0, 0.8, time)
                        {
                            EasingFunction = easingFunction
                        };

                        gradientStop.BeginAnimation(GradientStop.OffsetProperty, offsetAnimation);
                    }
                    else
                    {
                        var time           = TimeSpan.FromMilliseconds(200);
                        var easingFunction = new CubicEase()
                        {
                            EasingMode = EasingMode.EaseOut
                        };

                        var opacityAnimation = new DoubleAnimation(0.0, time)
                        {
                            EasingFunction = easingFunction
                        };

                        brush.BeginAnimation(Brush.OpacityProperty, opacityAnimation);

                        var radiusAnimation = new DoubleAnimation(200.0, time)
                        {
                            EasingFunction = easingFunction
                        };

                        brush.BeginAnimation(RadialGradientBrush.RadiusXProperty, radiusAnimation);
                        brush.BeginAnimation(RadialGradientBrush.RadiusYProperty, radiusAnimation);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static void SetRevealBrushMode(DependencyObject obj, RevealBrushMode value)
 {
     obj.SetValue(RevealBrushModeProperty, value);
 }