コード例 #1
0
        async Task UpdateTogglePosition(bool animated = true)
        {
            _isToggling = true;

            uint duration = 100;
            var  easing   = IsToggled ? Easing.CubicIn : Easing.CubicOut;

            if (animated == false)
            {
                duration = 0;
            }


            var xPosition      = IsToggled ? (RoundedRectangle.WidthRequest - 2 - 2 - CircleDot.Width) : 0;
            var animationTasks = new List <Task>();

            animationTasks.Add(CircleDot.TranslateTo(xPosition, 0, duration, easing));

            var fromColor = RoundedRectangle.BackgroundColor;
            var toColor   = IsToggled ? OnColor : OffColor;

            animationTasks.Add(RoundedRectangle.ColorTo(fromColor, toColor, (color) =>
            {
                RoundedRectangle.BackgroundColor = color;
            }, duration, easing));

            await Task.WhenAll(animationTasks);

            CurrentColor = toColor;

            _isToggling = false;
        }