예제 #1
0
        private void OnClick(object sender, RoutedEventArgs e)
        {
            var easing = Window.Current.Compositor.CreateLinearEasingFunction();

            var scale1 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();

            scale1.InsertKeyFrame(1, Vector2.One, easing);
            scale1.InsertKeyFrame(0, Vector2.Zero, easing);
            //scale1.Duration = TimeSpan.FromMilliseconds(500);

            var scale2 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();

            scale2.InsertKeyFrame(1, Vector2.Zero, easing);
            scale2.InsertKeyFrame(0, Vector2.One, easing);
            //scale2.Duration = TimeSpan.FromMilliseconds(500);

            _triangle1.StartAnimation("Scale", scale1);
            _triangle2.StartAnimation("Scale", scale2);
        }
        private void Timer_Tick(object sender, object e)
        {
            var now = DateTime.Now;

            _batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
            var animation = _compositor.CreateScalarKeyFrameAnimation();
            var seconds   = (float)(int)now.TimeOfDay.TotalSeconds;

            // This works:
            //animation.InsertKeyFrame(0.00f, seconds * 6);
            //animation.InsertKeyFrame(1.00f, (seconds + 1) * 6);

            // Just an example of using expressions:
            animation.SetScalarParameter("start", seconds * 6);
            animation.InsertExpressionKeyFrame(0.00f, "start");
            animation.SetScalarParameter("delta", 6.0f);
            animation.InsertExpressionKeyFrame(1.00f, "start + delta");

            animation.Duration = TimeSpan.FromMilliseconds(900);
            _secondhandSpriteShape.StartAnimation(nameof(_secondhandSpriteShape.RotationAngleInDegrees), animation);
            _batch.End();
            _batch.Completed += Batch_Completed;
        }
예제 #3
0
        private void OnToggle(object sender, RoutedEventArgs e)
        {
            if (_visual == null)
            {
                return;
            }

            var show = IsChecked == true;

            var batch = Window.Current.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            batch.Completed += (s, args) =>
            {
                _visual.BorderMode = show /*&& Type == MenuButtonType.Dismiss*/ ? CompositionBorderMode.Soft : CompositionBorderMode.Hard;
            };

            if (Type == MenuButtonType.Back)
            {
                var angle = Window.Current.Compositor.CreateScalarKeyFrameAnimation();
                angle.InsertKeyFrame(0, show ? 0 : -180);
                angle.InsertKeyFrame(1, show ? 180 : 0);

                var start1 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();
                start1.InsertKeyFrame(show ? 0 : 1, new Vector2(0, 4.5f));
                start1.InsertKeyFrame(show ? 1 : 0, new Vector2(8.5f, 1.5f));

                var start3 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();
                start3.InsertKeyFrame(show ? 0 : 1, new Vector2(0, 12.5f));
                start3.InsertKeyFrame(show ? 1 : 0, new Vector2(8.5f, 15.5f));

                var end1 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();
                end1.InsertKeyFrame(show ? 0 : 1, new Vector2(16, 4.5f));
                end1.InsertKeyFrame(show ? 1 : 0, new Vector2(15.5f, 8.5f));

                var end3 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();
                end3.InsertKeyFrame(show ? 0 : 1, new Vector2(16, 12.5f));
                end3.InsertKeyFrame(show ? 1 : 0, new Vector2(15.5f, 8.5f));

                _visual.BorderMode = CompositionBorderMode.Soft;
                _visual.StartAnimation("RotationAngleInDegrees", angle);
                _shape1.Geometry.StartAnimation("Start", start1);
                _shape3.Geometry.StartAnimation("Start", start3);
                _shape1.Geometry.StartAnimation("End", end1);
                _shape3.Geometry.StartAnimation("End", end3);
            }
            else if (Type == MenuButtonType.Dismiss)
            {
                var angle2 = Window.Current.Compositor.CreateScalarKeyFrameAnimation();
                angle2.InsertKeyFrame(show ? 0 : 1, 0);
                angle2.InsertKeyFrame(show ? 1 : 0, 90 + 45);

                var angle1 = Window.Current.Compositor.CreateScalarKeyFrameAnimation();
                angle1.InsertKeyFrame(show ? 0 : 1, 0);
                angle1.InsertKeyFrame(show ? 1 : 0, 90);

                var offset1 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();
                offset1.InsertKeyFrame(show ? 0 : 1, Vector2.Zero);
                offset1.InsertKeyFrame(show ? 1 : 0, new Vector2(0.5f, 4));

                var offset2 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();
                offset2.InsertKeyFrame(show ? 0 : 1, Vector2.Zero);
                offset2.InsertKeyFrame(show ? 1 : 0, new Vector2(0, -0.5f));

                var offset3 = Window.Current.Compositor.CreateVector2KeyFrameAnimation();
                offset3.InsertKeyFrame(show ? 0 : 1, Vector2.Zero);
                offset3.InsertKeyFrame(show ? 1 : 0, new Vector2(0.5f, -4));

                var opacity3 = Window.Current.Compositor.CreateColorKeyFrameAnimation();
                opacity3.InsertKeyFrame(show ? 0 : 1, Color.FromArgb(0xff, 0xff, 0xff, 0xff));
                opacity3.InsertKeyFrame(show ? 1 : 0, Color.FromArgb(0x00, 0xff, 0xff, 0xff));

                var opacityContent = Window.Current.Compositor.CreateScalarKeyFrameAnimation();
                opacityContent.InsertKeyFrame(show ? 0 : 1, 1);
                opacityContent.InsertKeyFrame(show ? 1 : 0, 0);

                _content?.StartAnimation("Opacity", opacityContent);

                _shape3.StrokeBrush.StartAnimation("Color", opacity3);

                _visual.BorderMode = CompositionBorderMode.Soft;
                _visual.StartAnimation("RotationAngleInDegrees", angle2);
                _shape1.StartAnimation("RotationAngleInDegrees", angle1);
                _shape3.StartAnimation("RotationAngleInDegrees", angle1);
                _shape1.StartAnimation("Offset", offset1);
                _shape2.StartAnimation("Offset", offset2);
                _shape3.StartAnimation("Offset", offset3);
            }

            batch.End();
        }