private void UpdateControlVertically() { var diffValue = NewHeight - ActualHeight; var animationTimeSpan = AnimationHeightGrowTimeMs; double animationTranformTimeSpan = AnimationTranformNegativeValueTimeMs; KeySpline fromKeySpline; KeySpline toKeySpline; double valueChange; if (diffValue >= 0) { valueChange = GetNegativeChange(ParentHeight, EndPoint.Y, diffValue, CurrentPoint.Y); fromKeySpline = new KeySpline(0.2, 0.16, 0.07, 1); toKeySpline = new KeySpline(0.32, 0.13, 0.18, 1); } else { animationTimeSpan = AnimationHeightShrinkTimeMs; animationTranformTimeSpan = AnimationTranformPositiveValueTimeMs; valueChange = GetPositiveChange(ParentHeight, _currentYoffSet, NewHeight, OriginalPoint.Y); fromKeySpline = new KeySpline(0.38, 0.38, 0.15, 0.98); toKeySpline = new KeySpline(0.23, 0.12, 0, 1); } if (_currentYoffSet + valueChange > CurrentMaxHeight) { valueChange = 0; } _currentYoffSet = _currentYoffSet + valueChange; ResizeHeightAnimation(animationTimeSpan, toKeySpline, fromKeySpline); UpdateTransformYAnimation(animationTranformTimeSpan); }
void ResizeWidthAnimation(double animationTimeSpan, KeySpline toKeySpline, KeySpline fromKeySpline, int beginTimeDelay) { var widthChangeAnimation = AnimationFactory.CreateDoubleAnimation(this, WidthProperty, toKeySpline, NewWidth, ActualWidth, fromKeySpline, durationSpan: TimeSpan.FromMilliseconds(animationTimeSpan), beginTimeSpan: TimeSpan.FromMilliseconds(beginTimeDelay)); widthChangeAnimation.Completed += WidthChangeAnimationCompleted; BeginAnimation(WidthProperty, widthChangeAnimation); }
//public static KeySpline CreateKeySpline(CubicBezierControlPoints controlPoints) //{ // return new KeySpline() // { // ControlPoint1 = Point(controlPoints.ControlPoint1), // ControlPoint2 = Point(controlPoints.ControlPoint2) // }; //} //public static KeySpline ToKeySpline(this CubicBezierControlPoints controlPoints) // => CreateKeySpline(controlPoints); public static KeySpline Reverse(this KeySpline keySpline) { return(new KeySpline { ControlPoint1 = new Point(keySpline.ControlPoint1.Y, keySpline.ControlPoint1.X), ControlPoint2 = new Point(keySpline.ControlPoint2.Y, keySpline.ControlPoint2.X) }); }
private static KeySpline DefineKeySpline(double cp1X, double cp1Y, double cp2X, double cp2Y) { KeySpline ksStart = new KeySpline(); ksStart.ControlPoint1 = new Point(cp1X, cp1Y); ksStart.ControlPoint2 = new Point(cp2X, cp2Y); return(ksStart); }
public static KeySpline Clone(this KeySpline keySpline) { return(new KeySpline { ControlPoint1 = keySpline.ControlPoint1, ControlPoint2 = keySpline.ControlPoint2 }); }
static NavigationTransitionInfo() { AccelerateKeySpline = new KeySpline(0.7, 0, 1, 0.5); AccelerateKeySpline.Freeze(); DecelerateKeySpline = new KeySpline(0.1, 0.9, 0.2, 1); DecelerateKeySpline.Freeze(); }
/// <summary> /// Initializes a new instance of the <see cref="SplineKeyFrame{T}" /> class with the specified ending value, key /// time, and <see cref="KeySpline" />. /// </summary> /// <param name="keySpline"> /// <see cref="KeySpline" /> for the key frame. The <see cref="KeySpline" /> represents a Bezier /// curve which defines animation progress of the key frame. /// </param> /// <param name="value">Ending value (also known as "target value") for the key frame.</param> /// <param name="keyTime"> /// Key time for the key frame. The key time determines when the target value is reached which is /// also when the key frame ends. /// </param> protected SplineKeyFrame(T value, KeyTime keyTime, KeySpline keySpline) : this(value, keyTime) { if (keySpline == null) { throw new ArgumentNullException("keySpline"); } KeySpline = keySpline; }
public static SplineDoubleKeyFrame EaseOut() { SplineDoubleKeyFrame sdkf = new SplineDoubleKeyFrame(); KeySpline ks = new KeySpline(); ks.ControlPoint1 = new Point(0, 0); ks.ControlPoint2 = new Point(0.58, 1); sdkf.KeySpline = ks; return(sdkf); }
public static SplineDoubleKeyFrame FastOut() { SplineDoubleKeyFrame sdkf = new SplineDoubleKeyFrame(); KeySpline ks = new KeySpline(); ks.ControlPoint1 = new Point(0.9, 0.1); ks.ControlPoint2 = new Point(1, 0.2); sdkf.KeySpline = ks; return(sdkf); }
public static SplineDoubleKeyFrame DrillIn() { SplineDoubleKeyFrame sdkf = new SplineDoubleKeyFrame(); KeySpline ks = new KeySpline(); ks.ControlPoint1 = new Point(0.17, 0.17); ks.ControlPoint2 = new Point(0, 1); sdkf.KeySpline = ks; return(sdkf); }
private static bool FastStringToKeySpline(Type outputType, string input, ref object output) { if (outputType == typeof(KeySpline)) { output = KeySpline.FromString(input); return(true); } return(false); }
public static SplineDoubleKeyFrame Custom(double x1, double y1, double x2, double y2) { SplineDoubleKeyFrame sdkf = new SplineDoubleKeyFrame(); KeySpline ks = new KeySpline(); ks.ControlPoint1 = new Point(x1, y1); ks.ControlPoint2 = new Point(x2, y2); sdkf.KeySpline = ks; return(sdkf); }
public void Reset() { this.lastEvaluatedTime = -1.0; this.keyFrameEnumerator.Reset(); this.curSegmentStartTime = -1.0; this.curSegmentEndTime = -1.0; this.curSegmentStartValue = new double?(); this.curSegmentEndValue = new double?(); this.keySpline = (KeySpline)null; this.easingFunction = (IEasingFunctionDefinition)null; }
/// <summary> /// Animates the <see cref="AreaSeries3D"/>. /// </summary> internal override void Animate() { // WPF-25124 Animation not working properly when resize the window. if (this.AnimationStoryboard != null) { AnimationStoryboard.Stop(); if (!this.canAnimate) { this.ResetAdornmentAnimationState(); return; } } this.AnimationStoryboard = new Storyboard(); foreach (AreaSegment3D segment in this.Segments) { var dblAnimationKeyFrames = new DoubleAnimationUsingKeyFrames(); var keyFrame = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = this.ActualYAxis.VisibleRange.Start }; dblAnimationKeyFrames.KeyFrames.Add(keyFrame); keyFrame = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(AnimationDuration), Value = this.Area.InternalSecondaryAxis.VisibleRange.End }; EasingDoubleKeyFrame ease = new EasingDoubleKeyFrame(); ease.Value = this.YValues.Max(); ease.KeyTime = this.AnimationDuration; ease.EasingFunction = new CircleEase(); var keySpline = new KeySpline { ControlPoint1 = new Point(0.64, 0.84), ControlPoint2 = new Point(0.67, 0.95) }; keyFrame.KeySpline = keySpline; dblAnimationKeyFrames.KeyFrames.Add(ease); dblAnimationKeyFrames.KeyFrames.Add(keyFrame); Storyboard.SetTargetProperty(dblAnimationKeyFrames, "AreaSegment3D.Y"); dblAnimationKeyFrames.EnableDependentAnimation = true; Storyboard.SetTarget(dblAnimationKeyFrames, segment); AnimationStoryboard.Children.Add(dblAnimationKeyFrames); } AnimationStoryboard.Begin(); }
/// <summary> /// Parses a Easing type string. /// </summary> /// <param name="e">The Easing type string.</param> /// <returns>Returns the instance of the parsed type.</returns> public static Easing Parse(string e) { #if NETSTANDARD2_0 if (e.Contains(",")) #else if (e.Contains(',')) #endif { return(new SplineEasing(KeySpline.Parse(e, CultureInfo.InvariantCulture))); } return(TryCreateEasingInstance(e, out var easing) ? easing : throw new FormatException($"Easing \"{e}\" was not found in {Namespace} namespace.")); }
protected override double[] InterpolateValueCore(double[] baseValue, double keyFrameProgress) { if (MathHelper.IsVerySmall(keyFrameProgress)) { return(baseValue); } if (MathHelper.AreClose(keyFrameProgress, 1)) { return(Numbers); } var splineProgress = KeySpline.GetSplineProgress(keyFrameProgress); return(AnimationHelper.InterpolateGeometryValue(baseValue, Numbers, splineProgress)); }
/// <summary> /// TypeConverter method implementation. /// </summary> /// <param name="context">ITypeDescriptorContext</param> /// <param name="cultureInfo">current culture (see CLR specs), null is a valid value</param> /// <param name="value">value to convert from</param> /// <param name="destinationType">Type to convert to</param> /// <returns>converted value</returns> /// <ExternalAPI/> public override object ConvertTo( ITypeDescriptorContext context, CultureInfo cultureInfo, object value, Type destinationType) { KeySpline keySpline = value as KeySpline; if (keySpline != null && destinationType != null) { if (destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(KeySpline).GetConstructor(new Type[] { typeof(double), typeof(double), typeof(double), typeof(double) }); return(new InstanceDescriptor(ci, new object[] { keySpline.ControlPoint1.X, keySpline.ControlPoint1.Y, keySpline.ControlPoint2.X, keySpline.ControlPoint2.Y })); } else if (destinationType == typeof(string)) { #pragma warning disable 56506 // Suppress presharp warning: Parameter 'cultureInfo.TextInfo' to this public method must be validated: A null-dereference can occur here. return(String.Format( cultureInfo, "{0}{4}{1}{4}{2}{4}{3}", keySpline.ControlPoint1.X, keySpline.ControlPoint1.Y, keySpline.ControlPoint2.X, keySpline.ControlPoint2.Y, cultureInfo != null ? cultureInfo.TextInfo.ListSeparator : CultureInfo.InvariantCulture.TextInfo.ListSeparator)); #pragma warning restore 56506 } } // Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.) return(base.ConvertTo(context, cultureInfo, value, destinationType)); }
private void Button_Click1(object sender, RoutedEventArgs e) { DoubleAnimationUsingKeyFrames dakX = new DoubleAnimationUsingKeyFrames(); //创建、添加关键帧 KeySpline ks = new KeySpline() { ControlPoint1 = new Point(0, 1), ControlPoint2 = new Point(1, 0) }; SplineDoubleKeyFrame kf = new SplineDoubleKeyFrame() { KeyTime = KeyTime.FromPercent(1), Value = 200, KeySpline = ks }; dakX.KeyFrames.Add(kf); //执行动画 this.tt.BeginAnimation(TranslateTransform.XProperty, dakX); }
private void AnimateAdornments() { if (this.AdornmentsInfo != null) { sb = new Storyboard(); double totalDuration = AnimationDuration.TotalSeconds; // UWP-185-RectAnimation takes some delay to render series. totalDuration *= 1.2; foreach (var child in this.AdornmentPresenter.Children) { DoubleAnimationUsingKeyFrames keyFrames1 = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame frame1 = new SplineDoubleKeyFrame(); frame1.KeyTime = TimeSpan.FromSeconds(0); frame1.Value = 0; keyFrames1.KeyFrames.Add(frame1); frame1 = new SplineDoubleKeyFrame(); frame1.KeyTime = TimeSpan.FromSeconds(totalDuration); frame1.Value = 0; keyFrames1.KeyFrames.Add(frame1); frame1 = new SplineDoubleKeyFrame(); frame1.KeyTime = TimeSpan.FromSeconds(totalDuration + 1); frame1.Value = 1; keyFrames1.KeyFrames.Add(frame1); KeySpline keySpline = new KeySpline(); keySpline.ControlPoint1 = new Point(0.64, 0.84); keySpline.ControlPoint2 = new Point(0, 1); keyFrames1.EnableDependentAnimation = true; Storyboard.SetTargetProperty(keyFrames1, "(Opacity)"); frame1.KeySpline = keySpline; Storyboard.SetTarget(keyFrames1, child as FrameworkElement); sb.Children.Add(keyFrames1); } sb.Begin(); } }
private void UpdateControlHorizontally() { var beginTimeDelay = AnimationBeginTimeWidthGrowMs; var animationTimeSpan = AnimationWidthGrowTimeMs; double animationTranformTimeSpan = AnimationTranformNegativeValueTimeMs; KeySpline toKeySpline; var diffValue = (NewWidth - ActualWidth); double valueChange; if (diffValue >= 0) { valueChange = GetNegativeChange(ParentWidth, EndPoint.X, diffValue, CurrentPoint.X); Console.WriteLine(valueChange); toKeySpline = new KeySpline(0.32, 0.13, 0.18, 1); } else { animationTimeSpan = AnimationWidthShrinkTimeMs; animationTranformTimeSpan = AnimationTranformPositiveValueTimeMs; valueChange = GetPositiveChange(ParentWidth, _currentXoffSet, NewWidth, OriginalPoint.X); toKeySpline = new KeySpline(0.38, 0.38, 0.15, 0.98); beginTimeDelay = 0; } if (_currentXoffSet + valueChange > CurrentMaxWidth) { valueChange = 0; } //Update current X value _currentXoffSet = _currentXoffSet + valueChange; ResizeWidthAnimation(animationTimeSpan, toKeySpline, null, beginTimeDelay); UpdateTransformXAnimation(animationTranformTimeSpan, beginTimeDelay); var content = GetTemplateChild(PartContentPresenter) as ContentPresenter; if (content != null && content.Opacity == 0) { FadeInContentAnimation(beginTimeDelay); } }
public static Storyboard FromTo(UIElement target, double from, double to, double duration, double delay, string prop, SplineDoubleKeyFrame ease = null, Action <object, object> onCompleteFunc = null) { if (ease == null) { ease = Easing.Linear(); } Storyboard sb = new Storyboard(); DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames();; EasingDoubleKeyFrame startFrame = new EasingDoubleKeyFrame(); EasingDoubleKeyFrame midFrame = new EasingDoubleKeyFrame(); SplineDoubleKeyFrame endFrame = new SplineDoubleKeyFrame(); KeySpline newKs = new KeySpline(); newKs.ControlPoint1 = ease.KeySpline.ControlPoint1; newKs.ControlPoint2 = ease.KeySpline.ControlPoint2; startFrame.Value = from; startFrame.KeyTime = TimeSpan.FromSeconds(0); midFrame.Value = from; midFrame.KeyTime = TimeSpan.FromMilliseconds(delay); endFrame.KeySpline = newKs; endFrame.Value = to; endFrame.KeyTime = TimeSpan.FromMilliseconds(delay + duration); anim.KeyFrames.Add(startFrame); anim.KeyFrames.Add(midFrame); anim.KeyFrames.Add(endFrame); anim.Duration = new Duration(TimeSpan.FromMilliseconds(delay + duration)); anim.EnableDependentAnimation = true; Storyboard.SetTarget(anim, target); Storyboard.SetTargetProperty(anim, prop); sb.Children.Add(anim); return(sb); }
private void btn_move_Click(object sender, RoutedEventArgs e) { //创建动画 DoubleAnimationUsingKeyFrames dukX = new DoubleAnimationUsingKeyFrames(); dukX.Duration = new Duration(TimeSpan.FromMilliseconds(1000)); //创建,添加关键帧 SplineDoubleKeyFrame kf = new SplineDoubleKeyFrame(); kf.KeyTime = KeyTime.FromPercent(1); kf.Value = 400; KeySpline ks = new KeySpline(); ks.ControlPoint1 = new Point(0, 1); ks.ControlPoint2 = new Point(1, 0); kf.KeySpline = ks; dukX.KeyFrames.Add(kf); //执行动画 tt_demo.BeginAnimation(TranslateTransform.XProperty, dukX); }
private void animateScroller(object objectToScroll) { AnimatedScrollViewer thisScrollViewer = objectToScroll as AnimatedScrollViewer; Duration targetTime = new Duration(thisScrollViewer.ScrollingTime); KeyTime targetKeyTime = thisScrollViewer.ScrollingTime; KeySpline targetKeySpline = thisScrollViewer.ScrollingSpline; DoubleAnimationUsingKeyFrames animateHScrollKeyFramed = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames animateVScrollKeyFramed = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame HScrollKey1 = new SplineDoubleKeyFrame(thisScrollViewer.TargetHorizontalOffset, targetKeyTime, targetKeySpline); SplineDoubleKeyFrame VScrollKey1 = new SplineDoubleKeyFrame(thisScrollViewer.TargetVerticalOffset, targetKeyTime, targetKeySpline); animateHScrollKeyFramed.KeyFrames.Add(HScrollKey1); animateVScrollKeyFramed.KeyFrames.Add(VScrollKey1); thisScrollViewer.BeginAnimation(HorizontalScrollOffsetProperty, animateHScrollKeyFramed); thisScrollViewer.BeginAnimation(VerticalScrollOffsetProperty, animateVScrollKeyFramed); CommandBindingCollection testCollection = thisScrollViewer.CommandBindings; int blah = testCollection.Count; }
private void AnimateNow() { if (AnimateScroll && Animations.ShouldAnimate) { KeyTime targetKeyTime = AnimateDuration; KeySpline targetKeySpline = AnimateSpline; DoubleAnimationUsingKeyFrames animateHScrollKeyFramed = new DoubleAnimationUsingKeyFrames(); animateHScrollKeyFramed.Completed += (s, e) => { _isHAnimating = false; }; DoubleAnimationUsingKeyFrames animateVScrollKeyFramed = new DoubleAnimationUsingKeyFrames(); animateVScrollKeyFramed.Completed += (s, e) => { _isVAnimating = false; }; SplineDoubleKeyFrame HScrollKey1 = new SplineDoubleKeyFrame(TargetHorizontalOffset, targetKeyTime, targetKeySpline); SplineDoubleKeyFrame VScrollKey1 = new SplineDoubleKeyFrame(TargetVerticalOffset, targetKeyTime, targetKeySpline); animateHScrollKeyFramed.KeyFrames.Add(HScrollKey1); animateVScrollKeyFramed.KeyFrames.Add(VScrollKey1); _isHAnimating = true; BeginAnimation(HorizontalScrollOffsetProperty, animateHScrollKeyFramed); _isVAnimating = true; BeginAnimation(VerticalScrollOffsetProperty, animateVScrollKeyFramed); //CommandBindingCollection testCollection = CommandBindings; //int blah = testCollection.Count; } else { _isHAnimating = true; HorizontalScrollOffset = TargetHorizontalOffset; _isHAnimating = false; _isVAnimating = true; VerticalScrollOffset = TargetVerticalOffset; _isVAnimating = false; } }
public static DoubleAnimationUsingKeyFrames CreateDoubleAnimation(KeySpline toKeySpline, double toValue, double fromValue = 0.0, KeySpline fromKeySpline = null, TimeSpan?beginTimeSpan = null, TimeSpan?durationSpan = null) { var duration = durationSpan != null ? durationSpan.Value : TimeSpan.FromSeconds(0); beginTimeSpan = beginTimeSpan != null ? beginTimeSpan.Value : TimeSpan.FromSeconds(0); var animation = new DoubleAnimationUsingKeyFrames { BeginTime = beginTimeSpan, Duration = duration, }; if (fromKeySpline == null) { animation.KeyFrames.Add(new SplineDoubleKeyFrame(fromValue, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); } else { animation.KeyFrames.Add(new SplineDoubleKeyFrame(fromValue, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), fromKeySpline)); } animation.KeyFrames.Add(new SplineDoubleKeyFrame(toValue, KeyTime.FromTimeSpan(duration), toKeySpline)); return(animation); }
/// <summary> /// Create Toggle Storyboard for Expanding and Collapsing the Window /// </summary> /// <param name="transform">TranslateTransform</param> /// <param name="sbName">Storyboard name used as Key in Resource Dictionary</param> /// <param name="fromValue">From value for Transform's Y Property</param> /// <param name="toValue">To value for Transform's Y Property</param> protected virtual void CreateToggleStoryboard(TranslateTransform transform, string sbName, double fromValue, double toValue) { Storyboard sb = new Storyboard(); sb.Completed += new EventHandler(ToggleAnimation_Completed); DoubleAnimationUsingKeyFrames dbAnimKF = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(dbAnimKF, transform); Storyboard.SetTargetProperty(dbAnimKF, new PropertyPath("Y")); dbAnimKF.BeginTime = TimeSpan.FromSeconds(0.0); SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame(); KeySpline spline = new KeySpline(); spline.ControlPoint1 = new Point(0, 0); spline.ControlPoint2 = new Point(0, 1); keyFrame.KeySpline = spline; keyFrame.KeyTime = TimeSpan.FromSeconds(0.75); keyFrame.Value = -fromValue; dbAnimKF.KeyFrames.Add(keyFrame); sb.Children.Add(dbAnimKF); this.Resources.Add(sbName, sb); }
internal void AnimateAdornments(Storyboard sb) { if (this.AdornmentsInfo != null) { double totalDuration = AnimationDuration.TotalSeconds; foreach (var child in this.AdornmentPresenter.Children) { DoubleAnimationUsingKeyFrames keyFrames1 = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame frame1 = new SplineDoubleKeyFrame(); frame1.KeyTime = TimeSpan.FromSeconds(0); frame1.Value = 0; keyFrames1.KeyFrames.Add(frame1); frame1 = new SplineDoubleKeyFrame(); frame1.KeyTime = TimeSpan.FromSeconds(totalDuration); frame1.Value = 0; keyFrames1.KeyFrames.Add(frame1); frame1 = new SplineDoubleKeyFrame(); frame1.KeyTime = TimeSpan.FromSeconds(totalDuration + 1); frame1.Value = 1; keyFrames1.KeyFrames.Add(frame1); KeySpline keySpline = new KeySpline(); keySpline.ControlPoint1 = new Point(0.64, 0.84); keySpline.ControlPoint2 = new Point(0, 1); // Animation have to provide same easing effect in all platforms. keyFrames1.EnableDependentAnimation = true; Storyboard.SetTargetProperty(keyFrames1, "(Opacity)"); frame1.KeySpline = keySpline; Storyboard.SetTarget(keyFrames1, child as FrameworkElement); sb.Children.Add(keyFrames1); } } }
private bool ConvertKeyFrameKeysplineToLocalValue(KeyFrameSceneNode keyFrame) { IPropertyId keySplineProperty = keyFrame.KeySplineProperty; if (keySplineProperty != null) { DocumentCompositeNode documentCompositeNode = keyFrame.DocumentNode as DocumentCompositeNode; if (documentCompositeNode != null) { DocumentNode expression = documentCompositeNode.Properties[keySplineProperty]; if (expression != null && expression.Type.IsResource) { DocumentNode documentNode = new ExpressionEvaluator(this.ViewModel.DocumentRootResolver).EvaluateExpression(this.ViewModel.ActiveEditingContainerPath, expression); if (documentNode != null) { KeySpline keySpline = (KeySpline)this.ViewModel.CreateInstance(new DocumentNodePath(documentNode, documentNode)); keyFrame.KeySpline = keySpline; return(true); } } } } return(false); }
internal override void Animate() { int i = 0, j = 0; // WPF-25124 Animation not working properly when resize the window. if (sb != null) { sb.Stop(); if (!canAnimate) { ResetAdornmentAnimationState(); return; } } sb = new Storyboard(); string path = IsActualTransposed ? "(UIElement.RenderTransform).(ScaleTransform.ScaleX)" : "(UIElement.RenderTransform).(ScaleTransform.ScaleY)"; string adornTransPath = IsActualTransposed ? "(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)" : "(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"; foreach (ChartSegment segment in Segments) { double elementHeight = 0d; var element = (FrameworkElement)segment.GetRenderedVisual(); if (segment is EmptyPointSegment && (!((segment as EmptyPointSegment).IsEmptySegmentInterior) || EmptyPointStyle == EmptyPointStyle.SymbolAndInterior)) { elementHeight = IsActualTransposed ? ((EmptyPointSegment)segment).EmptyPointSymbolWidth : ((EmptyPointSegment)segment).EmptyPointSymbolHeight; } else { elementHeight = IsActualTransposed ? ((ColumnSegment)segment).Width : ((ColumnSegment)segment).Height; } if (!double.IsNaN(elementHeight) && !double.IsNaN(YValues[i])) { if (element == null) { return; } var scaleTransform = new ScaleTransform(); element.RenderTransform = scaleTransform; if (this.CustomTemplate != null) { scaleTransform.CenterY = segment.rect.Y + elementHeight; } if (YValues[i] < 0 && IsActualTransposed) { element.RenderTransformOrigin = new Point(1, 1); } else if (YValues[i] > 0 && !IsActualTransposed) { element.RenderTransformOrigin = new Point(1, 1); } DoubleAnimationUsingKeyFrames keyFrames1 = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame keyFrame1 = new SplineDoubleKeyFrame(); keyFrame1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); keyFrame1.Value = 0; keyFrames1.KeyFrames.Add(keyFrame1); keyFrame1 = new SplineDoubleKeyFrame(); keyFrame1.KeyTime = KeyTime.FromTimeSpan(AnimationDuration); KeySpline keySpline1 = new KeySpline(); keySpline1.ControlPoint1 = new Point(0.64, 0.84); #if WINDOWS_UAP keySpline1.ControlPoint2 = new Point(0, 1); // Animation have to provide same easing effect in all platforms. #else keySpline1.ControlPoint2 = new Point(0.67, 0.95); #endif keyFrame1.KeySpline = keySpline1; keyFrames1.KeyFrames.Add(keyFrame1); keyFrame1.Value = 1; keyFrames1.EnableDependentAnimation = true; Storyboard.SetTargetProperty(keyFrames1, path); Storyboard.SetTarget(keyFrames1, element); sb.Children.Add(keyFrames1); if (this.AdornmentsInfo != null && AdornmentsInfo.ShowLabel) { FrameworkElement label = this.AdornmentsInfo.LabelPresenters[j]; var transformGroup = label.RenderTransform as TransformGroup; var translateTransform = new TranslateTransform(); if (transformGroup != null) { if (transformGroup.Children.Count > 0 && transformGroup.Children[0] is TranslateTransform) { transformGroup.Children[0] = translateTransform; } else { transformGroup.Children.Insert(0, translateTransform); } } keyFrames1 = new DoubleAnimationUsingKeyFrames(); keyFrame1 = new SplineDoubleKeyFrame(); keyFrame1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds((AnimationDuration.TotalSeconds * 80) / 100)); keyFrame1.Value = (YValues[i] > 0) ? (elementHeight * 10) / 100 : -(elementHeight * 10) / 100; keyFrames1.KeyFrames.Add(keyFrame1); keyFrame1 = new SplineDoubleKeyFrame(); keyFrame1.KeyTime = KeyTime.FromTimeSpan(AnimationDuration); keySpline1 = new KeySpline(); keySpline1.ControlPoint1 = new Point(0.64, 0.84); #if WINDOWS_UAP keySpline1.ControlPoint2 = new Point(0, 1); // Animation have to provide same easing effect in all platforms. #else keySpline1.ControlPoint2 = new Point(0.67, 0.95); #endif keyFrame1.KeySpline = keySpline1; keyFrames1.KeyFrames.Add(keyFrame1); keyFrame1.Value = 0; keyFrames1.EnableDependentAnimation = true; Storyboard.SetTargetProperty(keyFrames1, adornTransPath); Storyboard.SetTarget(keyFrames1, label); sb.Children.Add(keyFrames1); label.Opacity = 0; DoubleAnimation animation = new DoubleAnimation() { From = 0, To = 1, Duration = TimeSpan.FromSeconds((AnimationDuration.TotalSeconds * 20) / 100), BeginTime = TimeSpan.FromSeconds((AnimationDuration.TotalSeconds * 80) / 100) }; Storyboard.SetTarget(animation, label); Storyboard.SetTargetProperty(animation, "(UIElement.Opacity)"); sb.Children.Add(animation); j++; } } i++; } sb.Begin(); }
public override MyAnimateBase Animate() { IsAnimateCompleted = false; Element.RenderTransformOrigin = new Point(0.5, 0.5); Element.Visibility = Visibility.Visible; ScaleTransform translation = new ScaleTransform(1, 1); TranslateTransform translationTranslate = new TranslateTransform(0, 0); string translationName = ""; string translationTranslateName = ""; Storyboard story = new Storyboard(); DoubleAnimationUsingKeyFrames dauX = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames dauY = new DoubleAnimationUsingKeyFrames(); #region 基本工作,确定类型和name //是否存在TranslateTransform //动画要的类型是否存在 //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画 var ex = Element.RenderTransform; if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null) { var tg = new TransformGroup(); translation = new ScaleTransform(1, 1); translationName = "ayTranslation" + translation.GetHashCode(); Win.RegisterName(translationName, translation); tg.Children.Add(translation); translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode(); Win.RegisterName(translationTranslateName, translationTranslate); tg.Children.Add(translationTranslate); Element.RenderTransform = tg; } else { var tg = ex as TransformGroup; foreach (var item in tg.Children) { translation = item as ScaleTransform; if (translation != null) { break; } } foreach (var item in tg.Children) { translationTranslate = item as TranslateTransform; if (translationTranslate != null) { break; } } if (translation != null) { var tex = translation.GetValue(FrameworkElement.NameProperty); if (tex != null && tex.ToString() != "") { translationName = tex.ToString(); } else { translationName = "ayTranslation" + translation.GetHashCode(); Win.RegisterName(translationName, translation); } } else { translation = new ScaleTransform(1, 1); translationName = "ayTranslation" + translation.GetHashCode(); Win.RegisterName(translationName, translation); tg.Children.Add(translation); Element.RenderTransform = tg; } if (translationTranslate != null) { var tex = translationTranslate.GetValue(FrameworkElement.NameProperty); if (tex != null && tex.ToString() != "") { translationTranslateName = tex.ToString(); } else { translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode(); Win.RegisterName(translationTranslateName, translationTranslate); } } else { translationTranslate = new TranslateTransform(0, 0); translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode(); Win.RegisterName(translationTranslateName, translationTranslate); tg.Children.Add(translationTranslate); Element.RenderTransform = tg; } } #endregion var storyboardName = "aystory" + story.GetHashCode(); Win.Resources.Add(storyboardName, story); double danqianX = translation.ScaleX; double danqianY = translation.ScaleY; var keyspline = new KeySpline(0.55, 0.055, 0.675, 0.19); var keyspline2 = new KeySpline(0.175, 0.885, 0.320, 1); var k3_0 = new SplineDoubleKeyFrame(); k3_0.KeySpline = keyspline; k3_0.Value = 0.1; k3_0.KeyTime = TimeSpan.FromMilliseconds(0); var k3_1 = new SplineDoubleKeyFrame(); k3_1.KeySpline = keyspline2; k3_1.Value = 0.475; k3_1.KeyTime = TimeSpan.FromMilliseconds(AniTime(0.6)); var k3_2 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(1))); Storyboard.SetTargetName(dauX, translationName); Storyboard.SetTargetProperty(dauX, new PropertyPath(ScaleTransform.ScaleXProperty)); dauX.KeyFrames.Add(k3_0); dauX.KeyFrames.Add(k3_1); dauX.KeyFrames.Add(k3_2); story.Children.Add(dauX); var k4_0 = new SplineDoubleKeyFrame(); k4_0.KeySpline = keyspline; k4_0.Value = 0.1; k4_0.KeyTime = TimeSpan.FromMilliseconds(0); var k4_1 = new SplineDoubleKeyFrame(); k4_1.KeySpline = keyspline2; k4_1.Value = 0.475; k4_1.KeyTime = TimeSpan.FromMilliseconds(AniTime(0.6)); var k4_2 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(1))); Storyboard.SetTargetName(dauY, translationName); Storyboard.SetTargetProperty(dauY, new PropertyPath(ScaleTransform.ScaleYProperty)); dauY.KeyFrames.Add(k4_0); dauY.KeyFrames.Add(k4_1); dauY.KeyFrames.Add(k4_2); story.Children.Add(dauY); DoubleAnimationUsingKeyFrames dauTranslateY = new DoubleAnimationUsingKeyFrames(); var k5_0 = new SplineDoubleKeyFrame(); k5_0.KeySpline = keyspline; k5_0.Value = -1000; k5_0.KeyTime = TimeSpan.FromMilliseconds(0); var k5_1 = new SplineDoubleKeyFrame(); k5_1.KeySpline = keyspline2; k5_1.Value = 60; k5_1.KeyTime = TimeSpan.FromMilliseconds(AniTime(0.6)); var k5_2 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1))); Storyboard.SetTargetName(dauTranslateY, translationTranslateName); Storyboard.SetTargetProperty(dauTranslateY, new PropertyPath(TranslateTransform.YProperty)); dauTranslateY.KeyFrames.Add(k5_0); dauTranslateY.KeyFrames.Add(k5_1); dauTranslateY.KeyFrames.Add(k5_2); story.Children.Add(dauTranslateY); DoubleAnimationUsingKeyFrames dauOpacty = new DoubleAnimationUsingKeyFrames(); var k6 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(0))); var k6_1 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0.6))); dauOpacty.KeyFrames.Add(k6); dauOpacty.KeyFrames.Add(k6_1); Storyboard.SetTarget(dauOpacty, Element); dauOpacty.FillBehavior = FillBehavior.Stop; Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty)); story.Children.Add(dauOpacty); story.Completed += (sndr, evtArgs) => { try { Element.Opacity = 1; Win.Resources.Remove(storyboardName); Win.UnregisterName(translationName); dauX.KeyFrames.Clear(); dauX = null; dauY.KeyFrames.Clear(); dauY = null; story = null; base.CallClientCompleted(); } catch { } }; story.Begin(); return(this); }