protected override void OnConnected(UIElement element)
        {
            host    = ElementCompositionPreview.GetElementVisual(element);
            propset = host.Compositor.CreatePropertySet();
            propset.InsertScalar("offsetx", 0f);
            propset.InsertScalar("offsety", 0f);
            propset.InsertScalar("degress", 0f);
            propset.InsertVector3("axis", Vector3.UnitZ);

            UpdateTo();

            var group = host.Compositor.CreateAnimationGroup();

            var step = host.Compositor.CreateStepEasingFunction();

            offset = host.Compositor.CreateVector3KeyFrameAnimation();
            offset.InsertExpressionKeyFrame(0f, "this.StartingValue");
            offset.InsertExpressionKeyFrame(0.99f, "Vector3(this.FinalValue.X + prop.offsetx,this.FinalValue.Y + prop.offsety,this.FinalValue.Z)");
            offset.InsertExpressionKeyFrame(1f, "this.FinalValue", step);
            offset.SetReferenceParameter("host", host);
            offset.SetReferenceParameter("prop", propset);
            offset.Duration = Duration;
            offset.Target   = "Offset";

            axis = host.Compositor.CreateVector3KeyFrameAnimation();
            axis.InsertExpressionKeyFrame(0f, "prop.axis", step);
            axis.InsertExpressionKeyFrame(1f, "prop.axis", step);
            axis.SetReferenceParameter("prop", propset);
            axis.Duration = Duration;
            axis.Target   = "RotationAxis";

            degress = host.Compositor.CreateScalarKeyFrameAnimation();
            degress.InsertExpressionKeyFrame(0f, "this.StartingValue");
            degress.InsertExpressionKeyFrame(0.99f, "this.FinalValue + prop.degress");
            degress.InsertExpressionKeyFrame(1f, "this.FinalValue", step);
            degress.SetReferenceParameter("host", host);
            degress.SetReferenceParameter("prop", propset);
            degress.Duration = Duration;
            degress.Target   = "RotationAngleInDegrees";

            opacity = host.Compositor.CreateScalarKeyFrameAnimation();
            opacity.InsertExpressionKeyFrame(0f, "this.StartingValue");
            opacity.InsertKeyFrame(1f, 0f);
            opacity.Duration = Duration;
            opacity.Target   = "Opacity";

            group.Add(offset);
            group.Add(axis);
            group.Add(degress);
            group.Add(opacity);

            Animation = group;
        }
        protected override void OnConnected(UIElement element)
        {
            var host  = ElementCompositionPreview.GetElementVisual(element);
            var group = host.Compositor.CreateAnimationGroup();

            var step = host.Compositor.CreateStepEasingFunction();

            scale = host.Compositor.CreateVector3KeyFrameAnimation();
            scale.InsertExpressionKeyFrame(0f, "this.StartingValue");
            scale.InsertExpressionKeyFrame(0.99f, "Vector3(scalex,scaley,1f)");
            scale.InsertExpressionKeyFrame(1f, "this.FinalValue", step);
            scale.SetReferenceParameter("host", host);
            scale.SetScalarParameter("scalex", (float)ScaleX);
            scale.SetScalarParameter("scaley", (float)ScaleY);
            scale.Duration = Duration;
            scale.Target   = "Scale";

            opacity = host.Compositor.CreateScalarKeyFrameAnimation();
            opacity.InsertExpressionKeyFrame(0f, "this.StartingValue");
            opacity.InsertKeyFrame(0.99f, 0f);
            opacity.InsertKeyFrame(1f, 0f, step);
            opacity.Duration = Duration;
            opacity.Target   = "Opacity";

            group.Add(scale);
            group.Add(opacity);

            Animation = group;
        }
        protected override void OnConnected(UIElement element)
        {
            var host  = ElementCompositionPreview.GetElementVisual(element);
            var group = host.Compositor.CreateAnimationGroup();

            offset = host.Compositor.CreateVector3KeyFrameAnimation();
            offset.InsertExpressionKeyFrame(0f, "Vector3(this.StartingValue.X + offsetx,this.StartingValue.Y + offsety,this.StartingValue.Z)");
            offset.InsertExpressionKeyFrame(1f, "this.FinalValue");
            offset.SetReferenceParameter("host", host);
            offset.SetScalarParameter("offsetx", (float)OffsetX);
            offset.SetScalarParameter("offsety", (float)OffsetY);
            offset.Duration = Duration;
            offset.Target   = "Offset";

            opacity = host.Compositor.CreateScalarKeyFrameAnimation();
            opacity.InsertKeyFrame(0f, 0f);
            opacity.InsertExpressionKeyFrame(1f, "this.FinalValue");
            opacity.Duration = Duration;
            opacity.Target   = "Opacity";

            group.Add(offset);
            group.Add(opacity);

            Animation = group;
        }
 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);
 }
        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;
        }
示例#6
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);
        }