コード例 #1
0
        private async void ToggleAnimation()
        {
            this.Visibility = Visibility.Visible;

            if (Shown)
            {
                InputTB.Focus(FocusState.Programmatic);
            }

            await ContentGrid.WaitForNonZeroSizeAsync();

            _contentVisual.CenterPoint = new Vector3((float)(ContentGrid.ActualWidth / 2f), (float)(ContentGrid.ActualHeight / 2f), 1f);

            var maskAnimation = _compositor.CreateScalarKeyFrameAnimation();

            maskAnimation.InsertKeyFrame(1f, Shown ? 1f : 0f);
            maskAnimation.Duration = TimeSpan.FromMilliseconds(400);

            var contentAnimation = _compositor.CreateVector3KeyFrameAnimation();

            contentAnimation.InsertKeyFrame(0f, Shown ? new Vector3(1.2f, 1.2f, 1f) : new Vector3(1f, 1f, 1f));
            contentAnimation.InsertKeyFrame(1f, Shown ? new Vector3(1f, 1f, 1f) : new Vector3(1.2f, 1.2f, 1f));
            contentAnimation.Duration = TimeSpan.FromMilliseconds(400);

            var batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            _maskVisual.StartAnimation("Opacity", maskAnimation);
            _contentVisual.StartAnimation("Opacity", maskAnimation);
            _contentVisual.StartAnimation("Scale", contentAnimation);
            batch.Completed += (sender, e) =>
            {
                if (!Shown)
                {
                    this.Visibility = Visibility.Collapsed;
                }
            };
            batch.End();
        }