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; }
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.CreateScalarKeyFrameAnimation(); _animation.InsertExpressionKeyFrame(0.0f, "touch.Offset.X"); _animation.SetReferenceParameter("touch", _touchAreaVisual); }
void InitConpositionResources() { easing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.215f, 0.61f), new Vector2(0.355f, 1f)); steping = compositor.CreateStepEasingFunction(2); ProgressAnimation = compositor.CreateScalarKeyFrameAnimation(); ProgressAnimation.InsertExpressionKeyFrame(0f, "This.StartingValue", easing); ProgressAnimation.InsertExpressionKeyFrame(1f, "propSet.newvalue", easing); ProgressAnimation.SetReferenceParameter("propSet", propSet); ProgressAnimation.Duration = TimeSpan.FromSeconds(0.3d); ProgressAnimation.Target = "progress"; //ImplicitAnimations = compositor.CreateImplicitAnimationCollection(); //ImplicitAnimations["progress"] = ProgressAnimation; //propSet.ImplicitAnimations = ImplicitAnimations; TopBorderVisual = ElementCompositionPreview.GetElementVisual(TopBorder); BottomBorderVisual = ElementCompositionPreview.GetElementVisual(BottomBorder); CenterBorderVisual = ElementCompositionPreview.GetElementVisual(CenterBorder); ContentBorderVisual = ElementCompositionPreview.GetElementVisual(ContentBorder); TopBorderVisual.CenterPoint = new Vector3(38f, 36f, 0f); BottomBorderVisual.CenterPoint = new Vector3(39f, 36f, 0f); CenterBorderVisual.CenterPoint = new Vector3(36f, 36f, 0f); ContentBorderVisual.CenterPoint = new Vector3(36, 36, 0); TopRotationAnimation = compositor.CreateExpressionAnimation("0.25 * Pi * propSet.progress"); TopRotationAnimation.SetReferenceParameter("propSet", propSet); BottomRotationAnimation = compositor.CreateExpressionAnimation("-0.25 * Pi * propSet.progress"); BottomRotationAnimation.SetReferenceParameter("propSet", propSet); IconRotationAnimation = compositor.CreateExpressionAnimation("propSet.isopened == 1 ? -Pi * propSet.progress : Pi * propSet.progress"); IconRotationAnimation.SetReferenceParameter("propSet", propSet); ExternalScaleXAnimation = compositor.CreateExpressionAnimation(" 1 - 0.4 * propSet.progress"); ExternalScaleXAnimation.SetReferenceParameter("propSet", propSet); InternalScaleXAnimation = compositor.CreateExpressionAnimation(" 1 - 0.04 * propSet.progress"); InternalScaleXAnimation.SetReferenceParameter("propSet", propSet); IsOpenedAnimation = compositor.CreateScalarKeyFrameAnimation(); IsOpenedAnimation.InsertExpressionKeyFrame(0f, "This.StartingValue", steping); IsOpenedAnimation.InsertKeyFrame(1f, 1f, steping); IsOpenedAnimation.Duration = TimeSpan.FromSeconds(0.001d); IsOpenedAnimation.DelayTime = TimeSpan.FromSeconds(0.3d); IsNotOpenedAnimation = compositor.CreateScalarKeyFrameAnimation(); IsNotOpenedAnimation.InsertExpressionKeyFrame(0f, "This.StartingValue", steping); IsNotOpenedAnimation.InsertKeyFrame(1f, 0f, steping); IsNotOpenedAnimation.Duration = TimeSpan.FromSeconds(0.001d); IsNotOpenedAnimation.DelayTime = TimeSpan.FromSeconds(0.3d); TopBorderVisual.StartAnimation("RotationAngle", TopRotationAnimation); BottomBorderVisual.StartAnimation("RotationAngle", BottomRotationAnimation); ContentBorderVisual.StartAnimation("RotationAngle", IconRotationAnimation); TopBorderVisual.StartAnimation("Scale.X", ExternalScaleXAnimation); BottomBorderVisual.StartAnimation("Scale.X", ExternalScaleXAnimation); CenterBorderVisual.StartAnimation("Scale.X", InternalScaleXAnimation); }