void TouchArea_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
 {
     // reset the animation
     // todo: wonder if there should be a method to remove a certain key frame?
     // so I'd only need to remove the keyframe (_animation.InsertKeyFrame(1.0f, new Vector3());)
     // rather than create a new animation instance
     _x = 0.0f;
     _animation = _compositor.CreateVector3KeyFrameAnimation();
     _animation.InsertExpressionKeyFrame(0.0f, "touch.Offset");
     _animation.SetReferenceParameter("touch", _touchAreaVisual);
 }
Example #2
0
        private void ThumbnailList_ItemClick(object sender, ItemClickEventArgs e)
        {
            Thumbnail    thumbnail = (Thumbnail)e.ClickedItem;
            ListView     listView  = (ListView)sender;
            ListViewItem listItem  = (ListViewItem)listView.ContainerFromItem(e.ClickedItem);

            if (_zoomed)
            {
                Visual root = ElementCompositionPreview.GetElementVisual(ThumbnailList);

                //
                // Animate the rotation and offset back to the starting values
                //

                ScalarKeyFrameAnimation rotationAnimation = _compositor.CreateScalarKeyFrameAnimation();
                rotationAnimation.InsertKeyFrame(1, 0f);
                rotationAnimation.Duration = TimeSpan.FromMilliseconds(1000);
                root.StartAnimation("RotationAngleInDegrees", rotationAnimation);

                Vector3KeyFrameAnimation offsetAnimaton = _compositor.CreateVector3KeyFrameAnimation();
                offsetAnimaton.InsertKeyFrame(1, new Vector3(0, 0, 0));
                offsetAnimaton.Duration = TimeSpan.FromMilliseconds(1000);
                root.StartAnimation("Offset", offsetAnimaton);

                _zoomed = false;
            }
            else
            {
                //
                // Calculate the absolute offset to the item that was clicked.  We will use that for centering
                // the zoom in.
                //

                GeneralTransform coordinate = listItem.TransformToVisual(listView);
                Vector2          clickedItemCenterPosition = coordinate.TransformPoint(new Point(0, 0)).ToVector2() +
                                                             new Vector2((float)listItem.ActualWidth / 2, (float)listItem.ActualHeight / 2);


                //
                // Calculate the offset we want to animate up/down/in for the zoom based on the center point of the target and the
                // size of the panel/viewport.
                //

                Vector2 targetOffset = new Vector2((float)listView.ActualWidth / 2, (float)listView.ActualHeight / 2) - clickedItemCenterPosition;


                //
                // Get the root panel and set it up for the rotation animation.  We're rotating the listview around the Y-axis relative
                // to the center point of the panel.
                //

                Visual root = ElementCompositionPreview.GetElementVisual(ThumbnailList);
                root.Size         = new Vector2((float)ThumbnailList.ActualWidth, (float)ThumbnailList.ActualHeight);
                root.CenterPoint  = new Vector3(root.Size.X / 2, root.Size.Y / 2, 0);
                root.RotationAxis = new Vector3(0, 1, 0);

                // Kick off the rotation animation
                ScalarKeyFrameAnimation rotationAnimation = _compositor.CreateScalarKeyFrameAnimation();
                rotationAnimation.InsertKeyFrame(0, 0);
                rotationAnimation.InsertKeyFrame(1, targetOffset.X > 0 ? -45f : 45f);
                rotationAnimation.Duration = TimeSpan.FromMilliseconds(1000);
                root.StartAnimation("RotationAngleInDegrees", rotationAnimation);

                // Calcuate the offset for the point we are zooming towards
                const float zoomFactor   = .8f;
                Vector3     zoomedOffset = new Vector3(targetOffset.X, targetOffset.Y, (float)PerspectivePanel.ActualWidth * zoomFactor) * zoomFactor;

                Vector3KeyFrameAnimation offsetAnimaton = _compositor.CreateVector3KeyFrameAnimation();
                offsetAnimaton.InsertKeyFrame(0, new Vector3(0, 0, 0));
                offsetAnimaton.InsertKeyFrame(1, zoomedOffset);
                offsetAnimaton.Duration = TimeSpan.FromMilliseconds(1000);
                root.StartAnimation("Offset", offsetAnimaton);

                _zoomed = true;
            }
        }
Example #3
0
        private void UpdateAnimations()
        {
            Vector2 sizeLightBounds = new Vector2((float)RootPanel.ActualWidth, (float)RootPanel.ActualHeight);
            Vector3KeyFrameAnimation lightPositionAnimation;
            ColorKeyFrameAnimation   lightColorAnimation;

            ComboBoxItem item = LightingSelection.SelectedValue as ComboBoxItem;

            switch ((LightingTypes)item.Tag)
            {
            case LightingTypes.PointDiffuse:
            case LightingTypes.PointSpecular:
            {
                float zDistance = 50f;

                // Create the light position animation
                lightPositionAnimation = _compositor.CreateVector3KeyFrameAnimation();
                lightPositionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, zDistance));
                lightPositionAnimation.InsertKeyFrame(.25f, new Vector3(sizeLightBounds.X * .2f, sizeLightBounds.Y * .5f, zDistance));
                lightPositionAnimation.InsertKeyFrame(.50f, new Vector3(sizeLightBounds.X * .75f, sizeLightBounds.Y * .5f, zDistance));
                lightPositionAnimation.InsertKeyFrame(.75f, new Vector3(sizeLightBounds.X * .2f, sizeLightBounds.Y * .2f, zDistance));
                lightPositionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, zDistance));
                lightPositionAnimation.Duration          = TimeSpan.FromMilliseconds(7500);
                lightPositionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                lightColorAnimation = _compositor.CreateColorKeyFrameAnimation();
                lightColorAnimation.InsertKeyFrame(0f, Colors.White);
                lightColorAnimation.InsertKeyFrame(.33f, Colors.White);
                lightColorAnimation.InsertKeyFrame(.66f, Colors.Yellow);
                lightColorAnimation.InsertKeyFrame(1f, Colors.White);
                lightColorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
                lightColorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                _pointLight.StartAnimation("Offset", lightPositionAnimation);
                _pointLight.StartAnimation("Color", lightColorAnimation);
            }
            break;

            case LightingTypes.SpotLightDiffuse:
            case LightingTypes.SpotLightSpecular:
            {
                // Create the light position animation
                lightPositionAnimation = _compositor.CreateVector3KeyFrameAnimation();
                lightPositionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 100f));
                lightPositionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .5f, sizeLightBounds.Y * .5f, 200f));
                lightPositionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y * .5f, 400f));
                lightPositionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 100f));
                lightPositionAnimation.Duration          = TimeSpan.FromMilliseconds(7500);
                lightPositionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                lightColorAnimation = _compositor.CreateColorKeyFrameAnimation();
                lightColorAnimation.InsertKeyFrame(0f, Colors.White);
                lightColorAnimation.InsertKeyFrame(.33f, Colors.White);
                lightColorAnimation.InsertKeyFrame(.66f, Colors.Yellow);
                lightColorAnimation.InsertKeyFrame(1f, Colors.White);
                lightColorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
                lightColorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                _spotLight.StartAnimation("Offset", lightPositionAnimation);
                _spotLight.StartAnimation("InnerConeColor", lightColorAnimation);
            }
            break;

            case LightingTypes.DistantDiffuse:
            case LightingTypes.DistantSpecular:
            {
                // Animate the light direction
                Vector3 position  = new Vector3(0, 0, 100);
                float   offCenter = 700f;

                Vector3KeyFrameAnimation lightDirectionAnimation = _compositor.CreateVector3KeyFrameAnimation();
                lightDirectionAnimation.InsertKeyFrame(0f, Vector3.Normalize(new Vector3(0, 0, 0) - position));
                lightDirectionAnimation.InsertKeyFrame(.25f, Vector3.Normalize(new Vector3(offCenter, 0, 0) - position));
                lightDirectionAnimation.InsertKeyFrame(.5f, Vector3.Normalize(new Vector3(-offCenter, offCenter, 0) - position));
                lightDirectionAnimation.InsertKeyFrame(.75f, Vector3.Normalize(new Vector3(0, -offCenter, 0) - position));
                lightDirectionAnimation.InsertKeyFrame(1f, Vector3.Normalize(new Vector3(0, 0, 0) - position));
                lightDirectionAnimation.Duration          = TimeSpan.FromMilliseconds(7500);
                lightDirectionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                _distantLight.StartAnimation("Direction", lightDirectionAnimation);
            }
            break;

            default:
                break;
            }
        }
        /// <summary>
        /// Disposes the resources
        /// </summary>
        public void Dispose()
        {
            // Clean up resources
            _compositor = null;
            Source = null;
            DataContext = null;
            Foreground = null;
            Background = null;
            _scheduledObject = null;
            _currentObject = null;

            // Clean up Composition Objects
            _imageSurface?.Dispose();
            _imageSurface = null;
            _nextImageSurface?.Dispose();
            _nextImageSurface = null;
            _frameLayerMask?.Dispose();
            _frameLayerMask = null;
            _placeholderContentMask?.Dispose();
            _placeholderContentMask = null;
            _placeholderContentBrush?.Dispose();
            _placeholderContentBrush = null;
            _nextSurfaceBrush?.Dispose();
            _nextSurfaceBrush = null;
            _rootContainer?.Dispose();
            _rootContainer = null;
            _shadowVisual?.Dispose();
            _shadowVisual = null;
            _frameLayer?.Dispose();
            _frameLayer = null;
            _frameBackgroundVisual?.Dispose();
            _frameBackgroundVisual = null;
            _placeholderBackgroundVisual?.Dispose();
            _placeholderBackgroundVisual = null;
            _placeholderContentVisual?.Dispose();
            _placeholderContentVisual = null;
            _frameContentVisual?.Dispose();
            _frameContentVisual = null;
            _nextVisualContent?.Dispose();
            _nextVisualContent = null;
            _shadow?.Dispose();
            _shadow = null;
            _layerEffectBrush?.Dispose();
            _layerEffectBrush = null;
            _imageOptions = null;
            _zoomInAnimationGroup?.Dispose();
            _zoomInAnimationGroup = null;
            _fadeOutAnimation?.Dispose();
            _fadeOutAnimation = null;
            _fadeInAnimation?.Dispose();
            _fadeInAnimation = null;
            _colorAnimation?.Dispose();
            _colorAnimation = null;
            _alignXAnimation?.Dispose();
            _alignXAnimation = null;
            _alignYAnimation?.Dispose();
            _alignYAnimation = null;
            _offsetAnimation?.Dispose();
            _offsetAnimation = null;
            _scaleAnimation?.Dispose();
            _scaleAnimation = null;

            // Dispose the generator at the end to allow the 
            // dependant composition objects to unsubscribe from
            // generator events
            _generator?.Dispose();
            _generator = null;
        }
Example #5
0
        private void CreateAnimationTemplates(Compositor compositor)
        {
            //
            // Near-slide and far-slide animations.
            //

            _nearSlideOffsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            _nearSlideOffsetAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue");
            _nearSlideOffsetAnimation.InsertExpressionKeyFrame(1.0f, "vector3(0,0,0) - myViewportCenter");

            _farSlideOffsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            _farSlideOffsetAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue");
            _farSlideOffsetAnimation.InsertExpressionKeyFrame(0.9f, "vector3(0,0,0) - myViewportCenter");
            _farSlideOffsetAnimation.InsertExpressionKeyFrame(1.0f, "vector3(0,0,0) - myViewportCenter");

            _slideCenterAnimation = compositor.CreateVector3KeyFrameAnimation();
            _slideCenterAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue");
            _slideCenterAnimation.InsertExpressionKeyFrame(1.0f, "myTargetCenterPoint");

            _nearSlideScaleAnimation = compositor.CreateVector3KeyFrameAnimation();
            _nearSlideScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue");
            _nearSlideScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale");

            _farSlideScaleAnimation = compositor.CreateVector3KeyFrameAnimation();
            _farSlideScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue");
            _farSlideScaleAnimation.InsertKeyFrame(0.30f, new Vector3(1.0f, 1.0f, 1.0f));
            _farSlideScaleAnimation.InsertKeyFrame(1.00f, new Vector3(1.0f, 1.0f, 1.0f));

            TimeSpan time4sec = TimeSpan.FromSeconds(4);
            TimeSpan time8sec = TimeSpan.FromSeconds(8);
            _nearSlideOffsetAnimation.Duration = time4sec;
            _farSlideOffsetAnimation.Duration = time8sec;
            _slideCenterAnimation.Duration = time4sec;
            _nearSlideScaleAnimation.Duration = time4sec;
            _farSlideScaleAnimation.Duration = time4sec;

            //
            // Zoom animations.
            //

            _zoomScaleAnimation = compositor.CreateVector3KeyFrameAnimation();
            _zoomScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue");
            _zoomScaleAnimation.InsertKeyFrame(0.40f, new Vector3(1.0f, 1.0f, 1.0f));
            _zoomScaleAnimation.InsertKeyFrame(0.60f, new Vector3(1.0f, 1.0f, 1.0f));
            _zoomScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale");

            _zoomCenterAnimation = compositor.CreateVector3KeyFrameAnimation();
            _zoomCenterAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue");
            _zoomCenterAnimation.InsertExpressionKeyFrame(0.40f, "this.StartingValue");
            _zoomCenterAnimation.InsertExpressionKeyFrame(0.60f, "myTargetCenterPoint");
            _zoomCenterAnimation.InsertExpressionKeyFrame(1.00f, "myTargetCenterPoint");

            _zoomOffsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            _zoomOffsetAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue");
            _zoomOffsetAnimation.InsertExpressionKeyFrame(1.00f, "vector3(0,0,0) - myViewportCenter");

            TimeSpan time12sec = TimeSpan.FromSeconds(12);
            _zoomScaleAnimation.Duration = time12sec;
            _zoomCenterAnimation.Duration = time12sec;
            _zoomOffsetAnimation.Duration = time12sec;

            //
            // Stack animations.
            //

            CubicBezierEasingFunction flyInEasing;
            CubicBezierEasingFunction flyOutEasing;

            flyInEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 1.0f), new Vector2(0.8f, 1.0f));
            _stackFlyInAnimation = compositor.CreateVector3KeyFrameAnimation();
            _stackFlyInAnimation.InsertExpressionKeyFrame(0.00f, "stackVisual.Offset + startDelta");
            _stackFlyInAnimation.InsertExpressionKeyFrame(1.00f, "stackVisual.Offset + endDelta", flyInEasing);
            _stackFlyInAnimation.Duration = TimeSpan.FromSeconds(2);

            flyOutEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.4f), new Vector2(1.0f, 0.6f));
            _stackFlyOutAnimation = compositor.CreateVector3KeyFrameAnimation();
            _stackFlyOutAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue", flyOutEasing);
            _stackFlyOutAnimation.InsertExpressionKeyFrame(0.50f, "this.StartingValue + delta", flyOutEasing);
            _stackFlyOutAnimation.InsertExpressionKeyFrame(1.00f, "originalOffset", flyOutEasing);
            _stackFlyOutAnimation.Duration = TimeSpan.FromSeconds(2);

            _stackScaleAnimation = compositor.CreateVector3KeyFrameAnimation();
            _stackScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue");
            _stackScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale");
            _stackScaleAnimation.Duration = TimeSpan.FromSeconds(6);

            //
            // Color flashlight expression animation.
            //

            // This expression returns a computes between 0 and 1 as a function of on how close the
            // center of the frame is to the center of the window.
            //   - If the frame is at the center of the window, the expression computes 0 (no
            //     desaturation).
            //   - If the frame is more than 300px away from the center of the window, the
            //     expression computes 1 (full desaturation).
            //   - If the frame is within 300px from the center of the window, the expression
            //     computes a value between 0 and 1 relative to how far the frame is from the 300px
            //     boundary (partial desaturation).

            _colorFlashlightAnimation = compositor.CreateExpressionAnimation(
                  "1.0 - min("
                + "    1.0,"
                + "    ("
                + "        ("
                + "            ( frame.Offset.x + (frame.Size.x * 0.5) + grid.Offset.x - (windowWidth * 0.5) )"
                + "          * ( frame.Offset.x + (frame.Size.x * 0.5) + grid.Offset.x - (windowWidth * 0.5) )"
                + "        ) + ("
                + "            ( frame.Offset.y + (frame.Size.y * 0.5) + grid.Offset.y - (windowHeight * 0.5) )"
                + "          * ( frame.Offset.y + (frame.Size.y * 0.5) + grid.Offset.y - (windowHeight * 0.5) )"
                + "        )"
                + "    ) / ( radius * radius )"
                + ")");

            _colorFlashlightAnimation.SetReferenceParameter("grid", _layoutManager.GridVisual);
            _colorFlashlightAnimation.SetScalarParameter("radius", 300);
            _colorFlashlightAnimation.SetScalarParameter("windowWidth", _windowWidth);
            _colorFlashlightAnimation.SetScalarParameter("windowHeight", _windowHeight);
        }
Example #6
0
        public void TraitsTest()
        {
            var animationEx = new Vector3KeyFrameAnimation();

            Assert.AreEqual(Vector3Traits.Instance, animationEx.Traits);
        }
        public void Start(UIElement newParent, CompositionImage targetImage, ScrollViewer scrollViewer, UIElement animationTarget)
        {
            Visual transitionVisual = ElementCompositionPreview.GetElementChildVisual(_parent);

            ElementCompositionPreview.SetElementChildVisual(_parent, null);


            //
            // We need to reparent the transition visual under the new parent.  This is important to ensure
            // it's propertly clipped, etc.
            //

            GeneralTransform coordinate = newParent.TransformToVisual(_parent);
            Point            position   = coordinate.TransformPoint(new Point(0, 0));

            Vector3 currentOffset = transitionVisual.Offset;

            currentOffset.X        -= (float)position.X;
            currentOffset.Y        -= (float)position.Y;
            transitionVisual.Offset = currentOffset;

            _parent      = newParent;
            _targetImage = targetImage;

            // Move the transition visual to it's new parent
            ElementCompositionPreview.SetElementChildVisual(_parent, transitionVisual);

            // Hide the target Image now since the handoff visual is still transitioning
            targetImage.Opacity = 0f;

            // Load image if necessary
            _imageLoaded = targetImage.IsContentLoaded;
            if (!_imageLoaded)
            {
                targetImage.ImageOpened += CompositionImage_ImageOpened;
            }

            //
            // Create a scoped batch around the animations.  When the batch completes, we know the animations
            // have finished and we can cleanup the transition related objects.
            //

            Compositor compositor = transitionVisual.Compositor;

            _scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            //
            // Determine the offset between the parent and the target UIElement.  This will be used to calculate the
            // target position we are animating to.
            //

            coordinate = targetImage.TransformToVisual(_parent);
            position   = coordinate.TransformPoint(new Point(0, 0));

            TimeSpan totalDuration = TimeSpan.FromMilliseconds(1000);
            Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();

            if (scrollViewer != null)
            {
                CompositionPropertySet scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer);

                // Include the scroller offset as that is a factor
                position.X += scrollViewer.HorizontalOffset;
                position.Y += scrollViewer.VerticalOffset;


                //
                // Since the target position is relative to the target UIElement which can move, we need to construct
                // an expression to bind the target's position to the end position of our animation.
                //

                string expression = "Vector3(scrollingProperties.Translation.X, scrollingProperties.Translation.Y, 0) + itemOffset";
                offsetAnimation.InsertExpressionKeyFrame(1f, expression);
                offsetAnimation.SetReferenceParameter("scrollingProperties", scrollProperties);
                offsetAnimation.SetVector3Parameter("itemOffset", new Vector3((float)position.X, (float)position.Y, 0));
                offsetAnimation.Duration = totalDuration;
            }
            else
            {
                offsetAnimation.InsertKeyFrame(1, new Vector3((float)position.X, (float)position.Y, 0));
                offsetAnimation.Duration = totalDuration;
            }

            // Create size animation to change size of the visual
            Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation();

            sizeAnimation.InsertKeyFrame(1f, new Vector2((float)targetImage.ActualWidth, (float)targetImage.ActualHeight));
            sizeAnimation.Duration = totalDuration;

            // Create the fade in animation for the other page content
            if (animationTarget != null)
            {
                Visual fadeVisual = ElementCompositionPreview.GetElementVisual(animationTarget);
                ScalarKeyFrameAnimation fadeIn = compositor.CreateScalarKeyFrameAnimation();
                fadeIn.InsertKeyFrame(0f, 0.0f);
                fadeIn.InsertKeyFrame(1f, 1.0f);
                fadeIn.Duration = totalDuration;
                fadeVisual.StartAnimation("Opacity", fadeIn);
            }

            //Start Animations
            _sprite.StartAnimation("Size", sizeAnimation);
            _sprite.StartAnimation("Offset", offsetAnimation);

            //Scoped batch completed event
            _scopeBatch.Completed += ScopeBatch_Completed;
            _scopeBatch.End();

            // Clear the flag
            _animationCompleted = false;
        }
Example #8
0
        private void SetupInteraction()
        {
            if (DesignMode.DesignModeEnabled)
            {
                return;
            }
            if (Compositor == null)
            {
                return;
            }
            if (ContentBorderVisual == null)
            {
                return;
            }
            m_tracker = InteractionTracker.CreateWithOwner(Compositor, this);
            var height = (float)ContentBorder.ActualHeight;

            m_tracker.MaxPosition = new Vector3(0f, 0f, 0f);
            m_tracker.MinPosition = new Vector3(0f, -height, 0f);

            m_source = VisualInteractionSource.Create(ContentBorderVisual);
            m_source.IsPositionYRailsEnabled     = true;
            m_source.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;
            m_source.PositionYChainingMode       = InteractionChainingMode.Auto;
            m_source.PositionYSourceMode         = InteractionSourceMode.EnabledWithoutInertia;

            m_tracker.InteractionSources.Add(m_source);

            m_open              = InteractionTrackerInertiaRestingValue.Create(Compositor);
            m_open.Condition    = Compositor.CreateExpressionAnimation("this.Target.NaturalRestingPosition.Y > -host.Size.Y / 3");
            m_open.RestingValue = Compositor.CreateExpressionAnimation("0");
            m_open.Condition.SetReferenceParameter("host", ContentBorderVisual);
            m_open.RestingValue.SetReferenceParameter("host", ContentBorderVisual);

            m_close              = InteractionTrackerInertiaRestingValue.Create(Compositor);
            m_close.Condition    = Compositor.CreateExpressionAnimation("this.Target.NaturalRestingPosition.Y <= -host.Size.Y / 3");
            m_close.RestingValue = Compositor.CreateExpressionAnimation("-host.Size.Y");
            m_close.Condition.SetReferenceParameter("host", ContentBorderVisual);
            m_close.RestingValue.SetReferenceParameter("host", ContentBorderVisual);


            //Release模式会爆炸
            //var modifiers = new InteractionTrackerInertiaRestingValue[] { m_open, m_close };
            //m_tracker.ConfigurePositionYInertiaModifiers(modifiers);


            ContentOffsetExp = Compositor.CreateExpressionAnimation("Max(-15f, -tracker.Position.Y)");
            ContentOffsetExp.SetReferenceParameter("tracker", m_tracker);
            ContentBorderVisual.StartAnimation("Translation.Y", ContentOffsetExp);

            LightDismissLayerOpacityExp = Compositor.CreateExpressionAnimation("Clamp(1 + (tracker.Position.Y / host.Size.Y),0,1)");
            LightDismissLayerOpacityExp.SetReferenceParameter("tracker", m_tracker);
            LightDismissLayerOpacityExp.SetReferenceParameter("host", ContentBorderVisual);
            LightDismissLayerVisual.StartAnimation("Opacity", LightDismissLayerOpacityExp);

            OpenAnimation = Compositor.CreateVector3KeyFrameAnimation();
            OpenAnimation.InsertExpressionKeyFrame(0f, "Vector3(0f, -host.Size.Y, 0f)");
            OpenAnimation.InsertKeyFrame(1f, new Vector3(0f, 15f, 0f));
            OpenAnimation.SetReferenceParameter("host", ContentBorderVisual);
            OpenAnimation.Duration = TimeSpan.FromSeconds(0.3d);

            ToOpenAnimation = Compositor.CreateVector3KeyFrameAnimation();
            ToOpenAnimation.InsertKeyFrame(1f, new Vector3(0f, 5f, 0f));
            ToOpenAnimation.SetReferenceParameter("host", ContentBorderVisual);
            ToOpenAnimation.Duration = TimeSpan.FromSeconds(0.3d);

            CloseAnimation = Compositor.CreateVector3KeyFrameAnimation();
            CloseAnimation.InsertExpressionKeyFrame(1f, "Vector3(0f, -host.Size.Y, 0f)");
            CloseAnimation.SetReferenceParameter("host", ContentBorderVisual);
            CloseAnimation.Duration = TimeSpan.FromSeconds(0.3d);
        }
 public static Vector3KeyFrameAnimation SetDuration(this Vector3KeyFrameAnimation animation, TimeSpan duration)
 {
     animation.Duration = duration;
     return(animation);
 }
 public static Vector3KeyFrameAnimation SetDuration(this Vector3KeyFrameAnimation animation, double duration)
 {
     return(SetDuration(animation, TimeSpan.FromSeconds(duration)));
 }
 public static Vector3KeyFrameAnimation SetTarget(this Vector3KeyFrameAnimation animation, string target)
 {
     animation.Target = target;
     return(animation);
 }
        private async void ThumbnailList_ItemClick(object sender, ItemClickEventArgs e)
        {
            Thumbnail    thumbnail = (Thumbnail)e.ClickedItem;
            ListView     listView  = (ListView)sender;
            ListViewItem listItem  = (ListViewItem)listView.ContainerFromItem(e.ClickedItem);


            //
            // Calculate the absolute offset to the item that was clicked.  We will use that for centering
            // the zoom in.
            //

            GeneralTransform coordinate = listItem.TransformToVisual(RootPanel);
            Vector2          clickedItemCenterPosition = coordinate.TransformPoint(new Point(0, 0)).ToVector2() +
                                                         new Vector2((float)listItem.ActualWidth / 2, (float)listItem.ActualHeight / 2);


            //
            // Calculate the offset we want to animate up/down/in for the zoom based on the center point of the target and the
            // size of the panel/viewport.
            //
            Vector2 targetOffset = new Vector2((float)RootPanel.ActualWidth / 2, (float)RootPanel.ActualHeight / 2) - clickedItemCenterPosition;


            //
            // Get the root panel and set it up for the rotation animation.  We're rotating the listview around the Y-axis relative
            // to the center point of the panel.
            //

            Visual root = ElementCompositionPreview.GetElementVisual(ThumbnailList);

            root.Size         = new Vector2((float)ThumbnailList.ActualWidth, (float)ThumbnailList.ActualHeight);
            root.CenterPoint  = new Vector3(root.Size.X / 2, root.Size.Y / 2, 0);
            root.RotationAxis = new Vector3(0, 1, 0);

            // Kick off the rotation animation
            ScalarKeyFrameAnimation rotationAnimation = _compositor.CreateScalarKeyFrameAnimation();

            rotationAnimation.InsertKeyFrame(0, 0);
            rotationAnimation.InsertKeyFrame(1, targetOffset.X > 0 ? -45f : 45f);
            rotationAnimation.Duration = TimeSpan.FromMilliseconds(1000);
            root.StartAnimation("RotationAngleInDegrees", rotationAnimation);

            // Calcuate the offset for the point we are zooming towards
            const float zoomFactor   = .8f;
            Vector3     zoomedOffset = new Vector3(targetOffset.X * zoomFactor, // Adjust the x offset since the rotation will shorten the distance
                                                   targetOffset.Y,
                                                   (float)PerspectivePanel.ActualWidth * zoomFactor);

            Vector3KeyFrameAnimation offsetAnimaton = _compositor.CreateVector3KeyFrameAnimation();

            offsetAnimaton.InsertKeyFrame(0, new Vector3(0, 0, 0));
            offsetAnimaton.InsertKeyFrame(1, zoomedOffset);
            offsetAnimaton.Duration = TimeSpan.FromMilliseconds(1000);
            root.StartAnimation("Offset", offsetAnimaton);

            // Create the dialog
            var messageDialog = new MessageDialog(thumbnail.Name);

            messageDialog.Commands.Add(new UICommand("Close", new UICommandInvokedHandler(DialogDismissedHandler)));

            // Show the message dialog
            await messageDialog.ShowAsync();
        }
        /// <summary>
        /// Initializes the Composition elements
        /// </summary>
        private void InitComposition()
        {
            // Compositor
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            // CompositionGenerator
            _generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
            
            // Fade Out Animation
            _fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _fadeOutAnimation.InsertKeyFrame(1f, 0);
            _fadeOutAnimation.Duration = TransitionDuration;
            // Fade In Animation
            _fadeInAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _fadeInAnimation.InsertKeyFrame(1f, 1);
            _fadeInAnimation.Duration = TransitionDuration;
            // Color Animation
            _colorAnimation = _compositor.CreateColorKeyFrameAnimation();
            _colorAnimation.Duration = TransitionDuration;
            // Offset Animation
            _offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();
            _offsetAnimation.Target = "Offset";
            _offsetAnimation.Duration = TransitionDuration;
            _offsetAnimation.InsertKeyFrame(1f, Vector3.Zero);
            // Alignment animations
            _alignXAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _alignXAnimation.Duration = AlignmentTransitionDuration;
            _alignYAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _alignYAnimation.Duration = AlignmentTransitionDuration;

            // ZoomIn Animation Group
            _scaleAnimation = _compositor.CreateVector3KeyFrameAnimation();
            _scaleAnimation.Target = "Scale";
            _scaleAnimation.InsertKeyFrame(1f, Vector3.One);
            _scaleAnimation.Duration = TransitionDuration;
            _zoomInAnimationGroup = _compositor.CreateAnimationGroup();
            _zoomInAnimationGroup.Add(_scaleAnimation);
            _zoomInAnimationGroup.Add(_offsetAnimation);

            // Visuals
            _rootContainer = _compositor.CreateContainerVisual();
            _frameLayer = _compositor.CreateLayerVisual();
            _frameBackgroundVisual = _compositor.CreateSpriteVisual();
            _frameContentVisual = _compositor.CreateSpriteVisual();
            _placeholderContentVisual = _compositor.CreateSpriteVisual();
            _placeholderBackgroundVisual = _compositor.CreateSpriteVisual();
            _nextVisualContent = _compositor.CreateSpriteVisual();

            _frameLayer.Children.InsertAtTop(_frameBackgroundVisual);
            _frameLayer.Children.InsertAtTop(_frameContentVisual);
            _frameLayer.Children.InsertAtTop(_placeholderBackgroundVisual);
            _frameLayer.Children.InsertAtTop(_placeholderContentVisual);
            _frameLayer.Children.InsertAtTop(_nextVisualContent);

            // Placeholder content
            _placeholderContentMask = _generator.CreateGeometrySurface(PlaceholderSize, GetPlaceHolderGeometry(),
                PlaceholderColor, PlaceholderBackground);
            _placeholderContentBrush = _compositor.CreateSurfaceBrush(_placeholderContentMask.Surface);
            _placeholderContentVisual.Brush = _placeholderContentBrush;
            // Placeholder background
            _placeholderBackgroundVisual.Brush = _compositor.CreateColorBrush(PlaceholderBackground);

            // By default placeholder visual will not be visible
            HidePlaceholder();

            // Shadow visual
            _shadowVisual = _compositor.CreateSpriteVisual();

            _rootContainer.Children.InsertAtBottom(_shadowVisual);
            _rootContainer.Children.InsertAtTop(_frameLayer);

            _frameBackgroundVisual.Brush = _compositor.CreateColorBrush(FrameBackground);

            // Create the effect to create the opacity mask
            var layerEffect = new CompositeEffect
            {
                // CanvasComposite.DestinationIn - Intersection of source and mask. 
                // Equation: O = MA * S
                // where O - Output pixel, MA - Mask Alpha, S - Source pixel.
                Mode = CanvasComposite.DestinationIn,
                Sources =
                        {
                            new CompositionEffectSourceParameter("source"),
                            new CompositionEffectSourceParameter("mask")
                        }
            };

            var layerEffectFactory = _compositor.CreateEffectFactory(layerEffect);
            _layerEffectBrush = layerEffectFactory.CreateBrush();

            // The mask for the imageFrame
            _frameLayerMask = _generator.CreateMaskSurface(new Size(0, 0), null);
            _layerEffectBrush.SetSourceParameter("mask", _compositor.CreateSurfaceBrush(_frameLayerMask.Surface));
            // Apply the mask effect to the frameLayer
            _frameLayer.Effect = _layerEffectBrush;

            ElementCompositionPreview.SetElementChildVisual(this, _rootContainer);
        }
        private void CreateImageAndLights(Vector2 sizeLightBounds)
        {
            //
            // Image and effect setup
            //

            // Create the effect graph.  We will combine the desaturated image with two diffuse lights
            IGraphicsEffect graphicsEffect = new CompositeEffect()
            {
                Mode    = Microsoft.Graphics.Canvas.CanvasComposite.Add,
                Sources =
                {
                    new SaturationEffect()
                    {
                        Saturation = 0,
                        Source     = new CompositionEffectSourceParameter("ImageSource")
                    },

                    new PointDiffuseEffect()
                    {
                        Name          = "Light1",
                        DiffuseAmount = 1f,
                    },

                    new PointDiffuseEffect()
                    {
                        Name          = "Light2",
                        DiffuseAmount = 1f,
                    },
                }
            };

            // Create the effect factory, we're going to animate the light positions and colors
            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect,
                                                                                     new[] { "Light1.LightPosition", "Light1.LightColor",
                                                                                             "Light2.LightPosition", "Light2.LightColor", });

            // Create the effect brush and bind the normal map
            CompositionEffectBrush brush = effectFactory.CreateBrush();

            // Update the CompositionImage to use the custom effect brush
            ArtistImage.Brush = brush;


            //
            //  Animation setup
            //

            // Setup the first light's position, top and to the left in general
            LinearEasingFunction     linear            = _compositor.CreateLinearEasingFunction();
            Vector3KeyFrameAnimation positionAnimation = _compositor.CreateVector3KeyFrameAnimation();

            positionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 300f), linear);
            positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .5f, sizeLightBounds.Y * .5f, 100f), linear);
            positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .25f, sizeLightBounds.Y * .95f, 100f), linear);
            positionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 300f), linear);
            positionAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light1.LightPosition", positionAnimation);


            // Setup the first light's color animation, cycling through some brighter tones
            ColorKeyFrameAnimation colorAnimation = _compositor.CreateColorKeyFrameAnimation();

            colorAnimation.InsertKeyFrame(0f, Colors.Orange);
            colorAnimation.InsertKeyFrame(.2f, Colors.Orange);
            colorAnimation.InsertKeyFrame(.3f, Colors.Red);
            colorAnimation.InsertKeyFrame(.5f, Colors.Red);
            colorAnimation.InsertKeyFrame(.6f, Colors.Yellow);
            colorAnimation.InsertKeyFrame(.8f, Colors.Yellow);
            colorAnimation.InsertKeyFrame(.9f, Colors.Orange);
            colorAnimation.InsertKeyFrame(1f, Colors.Orange);
            colorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light1.LightColor", colorAnimation);


            // Setup the second light's position, down and to the right in general
            positionAnimation = _compositor.CreateVector3KeyFrameAnimation();
            positionAnimation.InsertKeyFrame(0f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear);
            positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .7f, sizeLightBounds.Y * .9f, 300f), linear);
            positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .95f, sizeLightBounds.Y * .95f, 100f), linear);
            positionAnimation.InsertKeyFrame(1f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear);
            positionAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light2.LightPosition", positionAnimation);

            // Setup the second light's color animation, cycling through some darker tones
            colorAnimation = _compositor.CreateColorKeyFrameAnimation();
            colorAnimation.InsertKeyFrame(0f, Colors.Blue);
            colorAnimation.InsertKeyFrame(.2f, Colors.Blue);
            colorAnimation.InsertKeyFrame(.3f, Colors.DarkGreen);
            colorAnimation.InsertKeyFrame(.5f, Colors.DarkGreen);
            colorAnimation.InsertKeyFrame(.6f, Colors.DarkBlue);
            colorAnimation.InsertKeyFrame(.8f, Colors.DarkBlue);
            colorAnimation.InsertKeyFrame(.9f, Colors.Blue);
            colorAnimation.InsertKeyFrame(1f, Colors.Blue);
            colorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light2.LightColor", colorAnimation);
        }
 public static Vector3KeyFrameAnimation AddKeyFrame(this Vector3KeyFrameAnimation animation, float normalizedProgressKey, Vector3 value, CompositionEasingFunction ease = null)
 {
     animation.InsertKeyFrame(normalizedProgressKey, value, ease);
     return(animation);
 }
        private void CreateTextAndBlendEffect(Vector2 sizeLightBounds)
        {
            //
            // Crete the effect graph, doing a hard light blend of the text over the
            // content already drawn into the backbuffer
            //

            IGraphicsEffect graphicsEffect = new BlendEffect()
            {
                Mode       = BlendEffectMode.HardLight,
                Foreground = new CompositionEffectSourceParameter("Text"),
                Background = new CompositionEffectSourceParameter("Destination"),
            };

            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
            CompositionEffectBrush   brush         = effectFactory.CreateBrush();

            // Bind the destination brush
            brush.SetSourceParameter("Destination", _compositor.CreateBackdropBrush());


            //
            // Create the text surface which we'll scroll over the image with the lighting effect
            //

            // Pick a nice size font depending on target size
            const float maxFontSize = 72;
            const float scaleFactor = 12;
            float       fontSize    = Math.Min(sizeLightBounds.X / scaleFactor, maxFontSize);

            // Create the text format description, then the surface
            CanvasTextFormat textFormat = new CanvasTextFormat
            {
                FontFamily          = "Segoe UI",
                FontSize            = fontSize,
                FontWeight          = FontWeights.Bold,
                WordWrapping        = CanvasWordWrapping.WholeWord,
                HorizontalAlignment = CanvasHorizontalAlignment.Center,
                VerticalAlignment   = CanvasVerticalAlignment.Center
            };

            string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec efficitur, eros sit amet laoreet scelerisque, " +
                          "nunc odio ultricies metus, ut consectetur nulla massa eu nibh.Phasellus in lorem id nunc euismod tempus.Phasellus et nulla non turpis tempor blandit ut eget turpis." +
                          "Phasellus ac ornare elit, ut scelerisque dolor. Nam vel finibus lorem. Aenean malesuada pulvinar eros id ornare. Fusce blandit ante eget dolor efficitur suscipit." +
                          "Phasellus ac lacus nibh. Aenean eget blandit risus, in lacinia mi. Proin fermentum ante eros, non sollicitudin mi pretium eu. Curabitur suscipit lectus arcu, eget" +
                          "pretium quam sagittis non. Mauris purus mauris, condimentum nec laoreet sit amet, imperdiet sit amet nisi. Sed interdum, urna et aliquam porta, elit velit tincidunt orci," +
                          "vitae vestibulum risus lacus at nulla.Phasellus sapien ipsum, pellentesque varius enim nec, iaculis aliquet enim. Nulla id dapibus ante. Sed hendrerit sagittis leo, commodo" +
                          "fringilla ligula rutrum ut. Nullam sodales, ex ut pellentesque scelerisque, sapien nulla mattis lectus, vel ullamcorper leo enim ac mi.Sed consectetur vitae velit in consequat." +
                          "Pellentesque ac condimentum justo, at feugiat nulla. Sed ut congue neque. Nam gravida quam ac urna porttitor, ut bibendum ante mattis.Cras viverra cursus sapien, et sollicitudin" +
                          "risus fringilla eget. Nulla facilisi. Duis pellentesque scelerisque nisi, facilisis malesuada massa gravida et. Vestibulum ac leo sed orci tincidunt feugiat.Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc id leo vestibulum, vulputate ipsum sit amet, scelerisque velit. Curabitur imperdiet justo et tortor dignissim, sit amet volutpat sem ullamcorper. Nam mollis ullamcorper tellus vitae convallis. Aliquam eleifend elit nec tincidunt pharetra. Aliquam turpis eros, mollis et nunc quis, porta molestie justo. Etiam ultrices sem non turpis imperdiet dictum.Aliquam molestie elit in urna sodales, nec luctus dui laoreet.Curabitur molestie risus vel ligula efficitur, non fringilla urna iaculis.Curabitur neque tortor, facilisis quis dictum facilisis, facilisis et ante. Sed nisl erat, semper vitae efficitur ut, congue vitae quam. Ut auctor lacus sit amet varius placerat.Sed ac tellus tempus, ultricies est quis, tempor felis.Nulla vel faucibus elit, eu tincidunt eros. Nulla blandit id nisl ut porta. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam suscipit tellus a mattis pulvinar. Sed et libero vel ligula elementum suscipit.Ut elementum libero at sagittis pharetra. Fusce ultrices odio sapien, a posuere est consectetur ut.";

            // Make the surface twice the height to give us room to scroll
            Vector2        surfaceSize = new Vector2(sizeLightBounds.X, 2f * sizeLightBounds.Y);
            ManagedSurface textSurface = ImageLoader.Instance.LoadText(text, surfaceSize.ToSize(),
                                                                       textFormat, Colors.White, Colors.Transparent);

            brush.SetSourceParameter("Text", textSurface.Brush);

            // Create the sprite and parent it to the panel with the clip
            _textSprite       = _compositor.CreateSpriteVisual();
            _textSprite.Size  = surfaceSize;
            _textSprite.Brush = brush;

            ElementCompositionPreview.SetElementChildVisual(MyPanel, _textSprite);

            // Lastly, setup the slow scrolling animation of the text
            LinearEasingFunction     linear          = _compositor.CreateLinearEasingFunction();
            Vector3KeyFrameAnimation offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(0f, new Vector3(0, 0, 0), linear);
            offsetAnimation.InsertKeyFrame(1f, new Vector3(0, -_textSprite.Size.Y * .5f, 0), linear);
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(30000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            _textSprite.StartAnimation("Offset", offsetAnimation);
        }
 public static Vector3KeyFrameAnimation AddKeyFrame(this Vector3KeyFrameAnimation animation, float normalizedProgressKey, float x, float y, float z, CompositionEasingFunction ease = null)
 {
     animation.InsertKeyFrame(normalizedProgressKey, new Vector3(x, y, z), ease);
     return(animation);
 }
Example #18
0
        private void UpdateAnimations()
        {
            Vector2 sizeLightBounds = new Vector2((float)RootPanel.ActualWidth, (float)RootPanel.ActualHeight + 200f);

            ComboBoxItem item = LightingSelection.SelectedValue as ComboBoxItem;

            switch ((LightingTypes)item.Tag)
            {
            case LightingTypes.PointDiffuse:
            case LightingTypes.PointSpecular:
            {
                // Create the light position animation
                _lightPositionAnimation = _compositor.CreateVector3KeyFrameAnimation();
                _lightPositionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 100f));
                _lightPositionAnimation.InsertKeyFrame(.25f, new Vector3(sizeLightBounds.X * .7f, sizeLightBounds.Y * .5f, 100f));
                _lightPositionAnimation.InsertKeyFrame(.50f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 100f));
                _lightPositionAnimation.InsertKeyFrame(.75f, new Vector3(sizeLightBounds.X * .2f, sizeLightBounds.Y, 100f));
                _lightPositionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 100f));
                _lightPositionAnimation.Duration          = TimeSpan.FromMilliseconds(7500);
                _lightPositionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                _lightColorAnimation = _compositor.CreateColorKeyFrameAnimation();
                _lightColorAnimation.InsertKeyFrame(0f, Colors.White);
                _lightColorAnimation.InsertKeyFrame(.33f, Colors.White);
                _lightColorAnimation.InsertKeyFrame(.66f, Colors.Yellow);
                _lightColorAnimation.InsertKeyFrame(1f, Colors.White);
                _lightColorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
                _lightColorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            }
            break;

            case LightingTypes.SpotLightDiffuse:
            case LightingTypes.SpotLightSpecular:
            {
                // Create the light position animation
                _lightPositionAnimation = _compositor.CreateVector3KeyFrameAnimation();
                _lightPositionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 100f));
                _lightPositionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .5f, sizeLightBounds.Y * .5f, 400f));
                _lightPositionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y * .5f, 1400f));
                _lightPositionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 100f));
                _lightPositionAnimation.Duration          = TimeSpan.FromMilliseconds(7500);
                _lightPositionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                _lightColorAnimation = _compositor.CreateColorKeyFrameAnimation();
                _lightColorAnimation.InsertKeyFrame(0f, Colors.White);
                _lightColorAnimation.InsertKeyFrame(.33f, Colors.White);
                _lightColorAnimation.InsertKeyFrame(.66f, Colors.Yellow);
                _lightColorAnimation.InsertKeyFrame(1f, Colors.White);
                _lightColorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
                _lightColorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            }
            break;

            case LightingTypes.DistantDiffuse:
            case LightingTypes.DistantSpecular:
            {
                _lightAzimuthAnimation = _compositor.CreateScalarKeyFrameAnimation();
                _lightAzimuthAnimation.InsertKeyFrame(0f, 0f);
                _lightAzimuthAnimation.InsertKeyFrame(1f, (float)Math.PI * 2f);
                _lightAzimuthAnimation.Duration          = TimeSpan.FromMilliseconds(10000);
                _lightAzimuthAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                _lightElevationAnimation = _compositor.CreateScalarKeyFrameAnimation();
                _lightElevationAnimation.InsertKeyFrame(0f, (float)Math.PI * .5f);
                _lightElevationAnimation.InsertKeyFrame(.33f, (float)Math.PI * .25f);
                _lightElevationAnimation.InsertKeyFrame(.66f, (float)Math.PI * .75f);
                _lightElevationAnimation.InsertKeyFrame(1f, (float)Math.PI * .5f);
                _lightElevationAnimation.Duration          = TimeSpan.FromMilliseconds(5000);
                _lightElevationAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            }
            break;

            default:
                break;
            }
        }
Example #19
0
 internal Vector3KeyFrameTransitionAnimationFluentContext([NotNull] StoryBoardFluentContext parentStoryBoard, [NotNull] Vector3KeyFrameAnimation animation, [NotNull] String targetProperty) : base(parentStoryBoard, animation, targetProperty)
 {
 }
Example #20
0
        private void Scroller4_ScrollAnimationStarting(muxc.ScrollViewer sender, muxc.ScrollAnimationStartingEventArgs args)
        {
            try
            {
                Vector3KeyFrameAnimation stockKeyFrameAnimation = args.Animation as Vector3KeyFrameAnimation;

                if (stockKeyFrameAnimation != null)
                {
                    Vector3KeyFrameAnimation customKeyFrameAnimation = stockKeyFrameAnimation;

                    if (nameof(ScrollAnimationOptions.Default) != (string)cbAnimation.SelectedItem)
                    {
                        double targetHorizontalOffset   = args.EndPosition.X;
                        float  targetHorizontalPosition = ComputeHorizontalPositionFromOffset(sender.Content, targetHorizontalOffset, sender.ZoomFactor);

                        double targetVerticalOffset   = args.EndPosition.Y;
                        float  targetVerticalPosition = ComputeVerticalPositionFromOffset(sender.Content, targetVerticalOffset, sender.ZoomFactor);

                        customKeyFrameAnimation = stockKeyFrameAnimation.Compositor.CreateVector3KeyFrameAnimation();

                        float deltaHorizontalPosition = (float)(targetHorizontalOffset - sender.HorizontalOffset);
                        float deltaVerticalPosition   = (float)(targetVerticalOffset - sender.VerticalOffset);

                        switch ((string)cbAnimation.SelectedItem)
                        {
                        case nameof(ScrollAnimationOptions.Custom1):
                            // "Accordion" case
                            for (int keyframe = 0; keyframe < 3; keyframe++)
                            {
                                customKeyFrameAnimation.InsertKeyFrame(
                                    1.0f - (0.4f / (float)Math.Pow(2, keyframe)),
                                    new Vector3(targetHorizontalPosition + 0.1f * deltaHorizontalPosition, targetVerticalPosition + 0.1f * deltaVerticalPosition, 0.0f));

                                deltaHorizontalPosition /= -2.0f;
                                deltaVerticalPosition   /= -2.0f;
                            }

                            customKeyFrameAnimation.InsertKeyFrame(1.0f, new Vector3(targetHorizontalPosition, targetVerticalPosition, 0.0f));
                            break;

                        case nameof(ScrollAnimationOptions.Custom2):
                            // "Teleportation" case
                            CubicBezierEasingFunction cubicBezierStart = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction(
                                new Vector2(1.0f, 0.0f),
                                new Vector2(1.0f, 0.0f));

                            StepEasingFunction step = stockKeyFrameAnimation.Compositor.CreateStepEasingFunction(1);

                            CubicBezierEasingFunction cubicBezierEnd = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction(
                                new Vector2(0.0f, 1.0f),
                                new Vector2(0.0f, 1.0f));

                            customKeyFrameAnimation.InsertKeyFrame(
                                0.499999f,
                                new Vector3(targetHorizontalPosition - 0.75f * deltaHorizontalPosition, targetVerticalPosition - 0.75f * deltaVerticalPosition, 0.0f),
                                cubicBezierStart);
                            customKeyFrameAnimation.InsertKeyFrame(
                                0.5f,
                                new Vector3(targetHorizontalPosition - 0.25f * deltaHorizontalPosition, targetVerticalPosition - 0.25f * deltaVerticalPosition, 0.0f),
                                step);
                            customKeyFrameAnimation.InsertKeyFrame(
                                1.0f,
                                new Vector3(targetHorizontalPosition, targetVerticalPosition, 0.0f),
                                cubicBezierEnd);
                            break;

                        default:
                            break;
                        }

                        customKeyFrameAnimation.Duration = stockKeyFrameAnimation.Duration;
                    }

                    if (!string.IsNullOrWhiteSpace(tbAnimDuration.Text))
                    {
                        // Override animation duration
                        double durationOverride = Convert.ToDouble(tbAnimDuration.Text);
                        customKeyFrameAnimation.Duration = TimeSpan.FromMilliseconds(durationOverride);
                    }

                    args.Animation = customKeyFrameAnimation;
                }
            }
            catch (Exception ex)
            {
            }
        }
        public static CompositionAnimation GetAnimation <TKeyFrame>(
            CompositionObject target,
            string property,
            TimeSpan?delay,
            TimeSpan duration,
            RepeatOption repeat,
            ReadOnlySpan <TKeyFrame> keyFrames)
            where TKeyFrame : struct, IKeyFrameInfo
        {
            KeyFrameAnimation animation;

            if (typeof(T) == typeof(bool))
            {
                BooleanKeyFrameAnimation boolAnimation = target.Compositor.CreateBooleanKeyFrameAnimation();

                foreach (ref readonly var keyFrame in keyFrames)
                {
                    if (keyFrame.TryInsertExpressionKeyFrame(boolAnimation, duration))
                    {
                        continue;
                    }

                    boolAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <bool>());
                }

                animation = boolAnimation;
            }
            else if (typeof(T) == typeof(float))
            {
                ScalarKeyFrameAnimation scalarAnimation = target.Compositor.CreateScalarKeyFrameAnimation();

                foreach (ref readonly var keyFrame in keyFrames)
                {
                    if (keyFrame.TryInsertExpressionKeyFrame(scalarAnimation, duration))
                    {
                        continue;
                    }

                    CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode);

                    if (easingFunction is null)
                    {
                        scalarAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <float>());
                    }
                    else
                    {
                        scalarAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <float>(), easingFunction);
                    }
                }

                animation = scalarAnimation;
            }
            else if (typeof(T) == typeof(double))
            {
                ScalarKeyFrameAnimation scalarAnimation = target.Compositor.CreateScalarKeyFrameAnimation();

                foreach (ref readonly var keyFrame in keyFrames)
                {
                    if (keyFrame.TryInsertExpressionKeyFrame(scalarAnimation, duration))
                    {
                        continue;
                    }

                    CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode);

                    if (easingFunction is null)
                    {
                        scalarAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), (float)keyFrame.GetValueAs <double>());
                    }
                    else
                    {
                        scalarAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), (float)keyFrame.GetValueAs <double>(), easingFunction);
                    }
                }

                animation = scalarAnimation;
            }
            else if (typeof(T) == typeof(Vector2))
            {
                Vector2KeyFrameAnimation vector2Animation = target.Compositor.CreateVector2KeyFrameAnimation();

                foreach (ref readonly var keyFrame in keyFrames)
                {
                    if (keyFrame.TryInsertExpressionKeyFrame(vector2Animation, duration))
                    {
                        continue;
                    }

                    CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode);

                    if (easingFunction is null)
                    {
                        vector2Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector2>());
                    }
                    else
                    {
                        vector2Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector2>(), easingFunction);
                    }
                }

                animation = vector2Animation;
            }
            else if (typeof(T) == typeof(Vector3))
            {
                Vector3KeyFrameAnimation vector3Animation = target.Compositor.CreateVector3KeyFrameAnimation();

                foreach (ref readonly var keyFrame in keyFrames)
                {
                    if (keyFrame.TryInsertExpressionKeyFrame(vector3Animation, duration))
                    {
                        continue;
                    }

                    CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode);

                    if (easingFunction is null)
                    {
                        vector3Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector3>());
                    }
                    else
                    {
                        vector3Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector3>(), easingFunction);
                    }
                }

                animation = vector3Animation;
            }
            else if (typeof(T) == typeof(Vector4))
            {
                Vector4KeyFrameAnimation vector4Animation = target.Compositor.CreateVector4KeyFrameAnimation();

                foreach (ref readonly var keyFrame in keyFrames)
                {
                    if (keyFrame.TryInsertExpressionKeyFrame(vector4Animation, duration))
                    {
                        continue;
                    }

                    CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode);

                    if (easingFunction is null)
                    {
                        vector4Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector4>());
                    }
                    else
                    {
                        vector4Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector4>(), easingFunction);
                    }
                }

                animation = vector4Animation;
            }
            else if (typeof(T) == typeof(Color))
            {
                ColorKeyFrameAnimation colorAnimation = target.Compositor.CreateColorKeyFrameAnimation();

                foreach (ref readonly var keyFrame in keyFrames)
                {
                    if (keyFrame.TryInsertExpressionKeyFrame(colorAnimation, duration))
                    {
                        continue;
                    }

                    CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode);

                    if (easingFunction is null)
                    {
                        colorAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Color>());
                    }
                    else
                    {
                        colorAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Color>(), easingFunction);
                    }
                }

                animation = colorAnimation;
            }
            else if (typeof(T) == typeof(Quaternion))
            {
                QuaternionKeyFrameAnimation quaternionAnimation = target.Compositor.CreateQuaternionKeyFrameAnimation();

                foreach (ref readonly var keyFrame in keyFrames)
                {
                    if (keyFrame.TryInsertExpressionKeyFrame(quaternionAnimation, duration))
                    {
                        continue;
                    }

                    CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode);

                    if (easingFunction is null)
                    {
                        quaternionAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Quaternion>());
                    }
                    else
                    {
                        quaternionAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Quaternion>(), easingFunction);
                    }
                }

                animation = quaternionAnimation;
            }
            else
            {
                return(ThrowHelper.ThrowInvalidOperationException <CompositionAnimation>("Invalid animation type"));
            }

            animation.Duration = duration;

            if (delay.HasValue)
            {
                animation.DelayTime = delay !.Value;
            }

            animation.Target = property;
            (animation.IterationBehavior, animation.IterationCount) = repeat.ToBehaviorAndCount();

            return(animation);
        }
Example #22
0
        public void Dispose()
        {
            if (_nearSlideOffsetAnimation != null)
            {
                _nearSlideOffsetAnimation.Dispose();
                _nearSlideOffsetAnimation = null;
            }

            if (_farSlideOffsetAnimation != null)
            {
                _farSlideOffsetAnimation.Dispose();
                _farSlideOffsetAnimation = null;
            }

            if (_slideCenterAnimation != null)
            {
                _slideCenterAnimation.Dispose();
                _slideCenterAnimation = null;
            }

            if (_zoomScaleAnimation != null)
            {
                _zoomScaleAnimation.Dispose();
                _zoomScaleAnimation = null;
            }

            if (_zoomCenterAnimation != null)
            {
                _zoomCenterAnimation.Dispose();
                _zoomCenterAnimation = null;
            }

            if (_zoomOffsetAnimation != null)
            {
                _zoomOffsetAnimation.Dispose();
                _zoomOffsetAnimation = null;
            }

            if (_stackFlyInAnimation != null)
            {
                _stackFlyInAnimation.Dispose();
                _stackFlyInAnimation = null;
            }

            if (_stackFlyOutAnimation != null)
            {
                _stackFlyOutAnimation.Dispose();
                _stackFlyOutAnimation = null;
            }

            if (_stackScaleAnimation != null)
            {
                _stackScaleAnimation.Dispose();
                _stackScaleAnimation = null;
            }

            if (_colorFlashlightAnimation != null)
            {
                _colorFlashlightAnimation.Dispose();
                _colorFlashlightAnimation = null;
            }
        }
        private void PlayingView_Loaded(object sender, RoutedEventArgs e)
        {
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }
            // get the private fields
            _rootGrid           = this.RootGrid;
            _rootGridVisual     = ElementCompositionPreview.GetElementVisual(this.RootGrid);
            _compositor         = _rootGridVisual.Compositor;
            _playerDiskVisual   = ElementCompositionPreview.GetElementVisual(this.playerDiskGrid);
            _playerNeedleVisual = ElementCompositionPreview.GetElementVisual(this.playerNeedle);
            //_coverBackImageVisual = ElementCompositionPreview.GetElementVisual(this.coverBGImage);
            this.backCanvasControl.CreateResources += BackCanvasControl_CreateResources;
            this.backCanvasControl.Draw            += BackCanvasControl_Draw;

            // prepare animations
            var liner = _compositor.CreateLinearEasingFunction();

            _openPlayingViewScaleAnimation = _compositor.CreateVector3KeyFrameAnimation();
            _openPlayingViewScaleAnimation.InsertKeyFrame(0.0f, new System.Numerics.Vector3(0.0f, 0f, 1f));
            _openPlayingViewScaleAnimation.InsertKeyFrame(1.0f, new System.Numerics.Vector3(1f, 1f, 1f), liner);
            _openPlayingViewScaleAnimation.Duration = TimeSpan.FromMilliseconds(300);

            _closePlayingViewScaleAnimation = _compositor.CreateVector3KeyFrameAnimation();
            _closePlayingViewScaleAnimation.InsertKeyFrame(0.0f, new System.Numerics.Vector3(1f, 1f, 1f));
            _closePlayingViewScaleAnimation.InsertKeyFrame(1.0f, new System.Numerics.Vector3(0f, 0f, 1f), liner);
            _closePlayingViewScaleAnimation.Duration = TimeSpan.FromMilliseconds(300);

            _closePlayingViewOpacityAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _closePlayingViewOpacityAnimation.InsertKeyFrame(0.0f, 1.0f);
            _closePlayingViewOpacityAnimation.InsertKeyFrame(1.0f, 0.3f, liner);
            _closePlayingViewOpacityAnimation.Duration = TimeSpan.FromMilliseconds(300);

            _openPlayingViewOpacityAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _openPlayingViewOpacityAnimation.InsertKeyFrame(0.0f, 0.3f);
            _openPlayingViewOpacityAnimation.InsertKeyFrame(1.0f, 1.0f, liner);
            _openPlayingViewOpacityAnimation.Duration = TimeSpan.FromMilliseconds(300);
            // Playing rotation animation
            _diskRotationAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _diskRotationAnimation.InsertKeyFrame(0.0f, 0f);
            _diskRotationAnimation.InsertKeyFrame(1f, 360.0f, liner);
            _diskRotationAnimation.Duration          = TimeSpan.FromSeconds(30);
            _diskRotationAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

            _needleStartAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _needleStartAnimation.InsertKeyFrame(0f, -30f);
            _needleStartAnimation.InsertKeyFrame(1f, 0f, liner);
            _needleStartAnimation.Duration = TimeSpan.FromMilliseconds(500);

            _needleStopAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _needleStopAnimation.InsertKeyFrame(0f, 0f);
            _needleStopAnimation.InsertKeyFrame(1f, -30f, liner);
            _needleStopAnimation.Duration = TimeSpan.FromMilliseconds(500);

            // set centerpoint
            _rootGridVisual.CenterPoint     = new System.Numerics.Vector3(0.0f, (float)RootGrid.ActualHeight, 0.0f);
            _playerDiskVisual.CenterPoint   = new System.Numerics.Vector3((float)(this.playerDiskGrid.ActualWidth / 2), (float)(this.playerDiskGrid.ActualHeight / 2), 0f);
            _playerNeedleVisual.CenterPoint = new System.Numerics.Vector3((float)(this.playerNeedle.ActualWidth / 2), 0f, 0f);


            // Set initial state of the visuals
            //_rootGridVisual.Scale = new System.Numerics.Vector3(0.0f, 0f, 1f);
            _playerNeedleVisual.RotationAngleInDegrees = -30f;

            // Note: Using storyboard instead of Composition API
            // Because blur appeares after compostion animation
            // It confused me!!
            _rootGrid.RenderTransform = new CompositeTransform()
            {
                ScaleX = 0, ScaleY = 0
            };

            // Set CoverBackground Effect; Don't support GaussionEffect!!
            //PrepareBlurCover();
        }
Example #24
0
 public void TraitsTest()
 {
     var animationEx = new Vector3KeyFrameAnimation();
       Assert.AreEqual(Vector3Traits.Instance, animationEx.Traits);
 }
Example #25
0
        void PrepareAnimation()
        {
            if (lowerThan14393)
            {
                _contentGrid.RenderTransformOrigin = new Point(0.5, 0.5);
                _contentGrid.RenderTransform       = new CompositeTransform();
                #region expand
                expand = new Storyboard();
                var duk = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = 1, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                expand.Children.Add(duk);

                duk = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = 1, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                expand.Children.Add(duk);

                duk = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.Rotation)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = -90
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = 0, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                expand.Children.Add(duk);
                #endregion

                #region collapse
                collapse = new Storyboard();
                duk      = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 1
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = 0, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                collapse.Children.Add(duk);

                duk = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 1
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = 0, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                collapse.Children.Add(duk);

                duk = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.Rotation)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = -90, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                collapse.Children.Add(duk);

                #endregion

                #region Open
                open = new Storyboard();
                duk  = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.1)), Value = 1, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                open.Children.Add(duk);

                duk = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.1)), Value = 1, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                open.Children.Add(duk);
                #endregion

                #region Close
                close = new Storyboard();
                duk   = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 1
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.07)), Value = 0, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                close.Children.Add(duk);

                duk = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(duk, _contentGrid);
                Storyboard.SetTargetProperty(duk, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 1
                });
                duk.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.07)), Value = 0, EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                close.Children.Add(duk);
                #endregion
            }
            else
            {
                //_radialMenuVisual = ElementCompositionPreview.GetElementVisual(this);
                //_radialMenuVisual.Offset = Offset;
                _contentGridVisual = ElementCompositionPreview.GetElementVisual(_contentGrid);
                _compositor        = _contentGridVisual.Compositor;

                rotationAnimation = _compositor.CreateScalarKeyFrameAnimation();
                scaleAnimation    = _compositor.CreateVector3KeyFrameAnimation();

                var easing = _compositor.CreateLinearEasingFunction();

                _contentGrid.SizeChanged += (s, e) =>
                {
                    _contentGridVisual.CenterPoint = new Vector3((float)_contentGrid.ActualWidth / 2.0f, (float)_contentGrid.ActualHeight / 2.0f, 0);
                };

                scaleAnimation.InsertKeyFrame(0.0f, new Vector3()
                {
                    X = 0.0f, Y = 0.0f, Z = 0.0f
                });
                scaleAnimation.InsertKeyFrame(1.0f, new Vector3()
                {
                    X = 1.0f, Y = 1.0f, Z = 0.0f
                }, easing);

                rotationAnimation.InsertKeyFrame(0.0f, -90.0f);
                rotationAnimation.InsertKeyFrame(1.0f, 0.0f, easing);
            }
        }