protected void PrepareAnimation(ContentControl view, double contentHeight, ChildWindowAnimation animationType = ChildWindowAnimation.None) { switch (animationType) { case ChildWindowAnimation.Fade: var fadeDa = new DoubleAnimation(0, 1, new Duration(defaultAnimationTime)); Storyboard.SetTarget(fadeDa, view); Storyboard.SetTargetProperty(fadeDa, new PropertyPath("Opacity")); var fadeSb = new Storyboard(); fadeSb.Children.Add(fadeDa); fadeSb.Begin(); break; case ChildWindowAnimation.Grown: var scale = new ScaleTransform(0.1, 0.1); var transformGroup = new TransformGroup(); transformGroup.Children.Add(scale); view.RenderTransform = transformGroup; view.RenderTransformOrigin = new Point(0.5, 0.5); var xScaleAnimation = new DoubleAnimationUsingKeyFrames(); var xKeyFrame = new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(defaultAnimationTime)); xScaleAnimation.KeyFrames = new DoubleKeyFrameCollection { xKeyFrame }; Storyboard.SetTarget(xScaleAnimation, view); Storyboard.SetTargetProperty(xScaleAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); var yScaleAnimation = new DoubleAnimationUsingKeyFrames(); var yKeyFrame = new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(defaultAnimationTime)); yScaleAnimation.KeyFrames = new DoubleKeyFrameCollection { yKeyFrame }; Storyboard.SetTarget(yScaleAnimation, view); Storyboard.SetTargetProperty(yScaleAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); var grownSb = new Storyboard(); grownSb.Children.Add(xScaleAnimation); grownSb.Children.Add(yScaleAnimation); grownSb.Begin(); break; case ChildWindowAnimation.Fall: view.Margin = new Thickness(0, (-1) * contentHeight, 0, contentHeight); var fallAnimation = new ThicknessAnimationUsingKeyFrames(); var fallKeyFrame = new EasingThicknessKeyFrame(new Thickness(0), KeyTime.FromTimeSpan(defaultAnimationTime)); fallAnimation.KeyFrames = new ThicknessKeyFrameCollection { fallKeyFrame }; Storyboard.SetTarget(fallAnimation, view); Storyboard.SetTargetProperty(fallAnimation, new PropertyPath("(FrameworkElement.Margin)")); var fallSb = new Storyboard(); fallSb.Children.Add(fallAnimation); fallSb.Begin(); break; } }
public override void CreateStoryboard() { ThicknessAnimationUsingKeyFrames dau = new ThicknessAnimationUsingKeyFrames(); EasingThicknessKeyFrame fromk = null; if (FromThickness.HasValue) { fromk = new EasingThicknessKeyFrame(FromThickness.Value, TimeSpan.FromMilliseconds(AniTime(0))); dau.KeyFrames.Add(fromk); } EasingThicknessKeyFrame tok = null; if (ToThickness.HasValue) { tok = new EasingThicknessKeyFrame(ToThickness.Value, TimeSpan.FromMilliseconds(AniTime(1))); dau.KeyFrames.Add(tok); } if (AniEasingFunction != null) { if (fromk != null) { fromk.EasingFunction = AniEasingFunction; } if (tok != null) { tok.EasingFunction = AniEasingFunction; } } else if (CirDefault != null) { if (fromk != null) { fromk.EasingFunction = CirDefault; } if (tok != null) { tok.EasingFunction = CirDefault; } } Storyboard.SetTarget(dau, Element); SetPropertyPath(FrameworkElement.MarginProperty); Storyboard.SetTargetProperty(dau, AniPropertyPath); Story.Children.Add(dau); }
public void addThicknessAnimation(String control, double a, double b, double c, double d, int duration) { ThicknessAnimationUsingKeyFrames anim = new ThicknessAnimationUsingKeyFrames(); EasingThicknessKeyFrame edkf = new EasingThicknessKeyFrame(); edkf.Value = new Thickness(a, b, c, d); edkf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(duration)); anim.KeyFrames.Add(edkf); anim.BeginTime = TimeSpan.FromSeconds(beginTime); beginTime += duration; if (duration > 0) { animTimer.Add(beginTime); } Storyboard.SetTargetName(anim, control); Storyboard.SetTargetProperty(anim, new PropertyPath(Control.MarginProperty)); sb.Children.Add(anim); }
void AssociatedObject_Drawed(object sender, RoutedEventArgs e) { var items = this.GetChildren <UIElement>().Where(l => l.RenderTransform is TransformGroup); items = items.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4); var controls = items?.ToList(); if (controls == null || controls.Count == 0) { return; } Storyboard storyboard = new Storyboard(); for (int i = 0; i < controls.Count; i++) { foreach (var item in Timelines.OfType <DoubleAnimation>()) { TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds)); TimeSpan end = item.Duration.TimeSpan + span; DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame key1 = new EasingDoubleKeyFrame(item.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero)); frames.KeyFrames.Add(key1); Storyboard.SetTarget(frames, controls[i]); Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item)); storyboard.Children.Add(frames); DoubleAnimation animation = item.Clone(); animation.BeginTime = span; Storyboard.SetTarget(animation, controls[i]); storyboard.Children.Add(animation); } foreach (var item in Timelines.OfType <ThicknessAnimation>()) { TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds)); TimeSpan end = item.Duration.TimeSpan + span; ThicknessAnimationUsingKeyFrames frames = new ThicknessAnimationUsingKeyFrames(); EasingThicknessKeyFrame key1 = new EasingThicknessKeyFrame(item.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero)); frames.KeyFrames.Add(key1); Storyboard.SetTarget(frames, controls[i]); Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item)); storyboard.Children.Add(frames); ThicknessAnimation animation = item.Clone(); animation.BeginTime = span; Storyboard.SetTarget(animation, controls[i]); storyboard.Children.Add(animation); } } storyboard.FillBehavior = FillBehavior.HoldEnd; storyboard.Begin(); }
protected sealed override void UpdateDots() { if (DotCount < 1) { return; } PrivateCanvas.Children.Clear(); //计算相关尺寸 var centerWidth = DotDiameter * DotCount + DotInterval * (DotCount - 1) + MoveLength; var speedDownLength = (ActualWidth - MoveLength) / 2; var speedUniformLength = centerWidth / 2; //定义动画 Storyboard = new Storyboard { RepeatBehavior = RepeatBehavior.Forever }; //创建圆点 for (var i = 0; i < DotCount; i++) { var ellipse = CreateEllipse(); var frames = new ThicknessAnimationUsingKeyFrames { BeginTime = TimeSpan.FromMilliseconds(DotDelayTime * i) }; //开始位置 var frame0 = new LinearThicknessKeyFrame { Value = new Thickness(ellipse.Margin.Left, 0, 0, 0), KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero) }; //开始位置到匀速开始 var frame1 = new EasingThicknessKeyFrame { EasingFunction = new PowerEase { EasingMode = EasingMode.EaseOut }, Value = new Thickness(speedDownLength + ellipse.Margin.Left, 0, 0, 0), KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(DotSpeed * (1 - UniformScale) / 2)) }; //匀速开始到匀速结束 var frame2 = new LinearThicknessKeyFrame { Value = new Thickness(speedDownLength + speedUniformLength + ellipse.Margin.Left, 0, 0, 0), KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(DotSpeed * (1 + UniformScale) / 2)) }; //匀速结束到匀加速结束 var frame3 = new EasingThicknessKeyFrame { EasingFunction = new PowerEase { EasingMode = EasingMode.EaseIn }, Value = new Thickness(ActualWidth + ellipse.Margin.Left + speedUniformLength, 0, 0, 0), KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(DotSpeed)) }; frames.KeyFrames.Add(frame0); frames.KeyFrames.Add(frame1); frames.KeyFrames.Add(frame2); frames.KeyFrames.Add(frame3); Storyboard.SetTarget(frames, ellipse); Storyboard.SetTargetProperty(frames, new PropertyPath(MarginProperty)); Storyboard.Children.Add(frames); PrivateCanvas.Children.Add(ellipse); } Storyboard.Begin(); }
private static void InlineOrOverlay(AySplitView sv, bool isOpenValue) { if (isOpenValue) //从隐藏到显示 { if (sv.LeftArea.IsNull()) { return; } { Thickness thickOld = new Thickness(sv.LeftArea.Width * (-1), 0, 0, 0); if (double.IsNaN(sv.OpenPaneLength)) { thickOld = new Thickness(sv.cc.RenderSize.Width * (-1), 0, 0, 0); } sv.LeftArea.Margin = thickOld; sv.LeftArea.Visibility = Visibility.Visible; Thickness thicnew = new Thickness(0, 0, 0, 0); ThicknessAnimationUsingKeyFrames taShow = new ThicknessAnimationUsingKeyFrames(); taShow.Duration = new Duration(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime)); taShow.FillBehavior = FillBehavior.Stop; taShow.Completed += (sender, ev) => { sv.LeftArea.Margin = thicnew; taShow = null; #region 触发客户端定义的事件 sv.OpenPaneCompletedChanged(); #endregion }; EasingThicknessKeyFrame taFrame = new EasingThicknessKeyFrame(thicnew, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime))); taShow.KeyFrames.Add(taFrame); sv.LeftArea.BeginAnimation(Grid.MarginProperty, taShow); } //if (sv.DisplayMode == SplitViewDisplayMode.Inline) //{ // { // Thickness thickOld = new Thickness(0 , 0, 0, 0); // sv.ContentArea.Margin = thickOld; // Thickness thicnew = new Thickness(sv.LeftArea.Width, 0, 0, 0); // if (double.IsNaN(sv.OpenPaneLength)) // { // thicnew = new Thickness(sv.cc.RenderSize.Width, 0, 0, 0); // } // sv.ContentArea.Margin = thicnew; // //ThicknessAnimationUsingKeyFrames taShow = new ThicknessAnimationUsingKeyFrames(); // //taShow.Duration = new Duration(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime)); // //taShow.FillBehavior = FillBehavior.Stop; // //taShow.Completed += (sender, ev) => // //{ // // sv.ContentArea.Margin = thicnew; // // taShow = null; // //}; // //EasingThicknessKeyFrame taFrame = new EasingThicknessKeyFrame(thicnew, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime))); // //taShow.KeyFrames.Add(taFrame); // //sv.LeftArea.BeginAnimation(Grid.MarginProperty, taShow); // } //} } else //显示到隐藏 { Thickness thickOld = new Thickness(0, 0, 0, 0); sv.LeftArea.Margin = thickOld; Thickness thicnew = new Thickness(sv.cc.RenderSize.Width * (-1), 0, 0, 0); if (!double.IsNaN(sv.OpenPaneLength)) { thicnew = new Thickness(sv.OpenPaneLength * (-1), 0, 0, 0); } ThicknessAnimationUsingKeyFrames taShow = new ThicknessAnimationUsingKeyFrames(); taShow.Duration = new Duration(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime)); taShow.FillBehavior = FillBehavior.Stop; taShow.Completed += (sender, ev) => { sv.LeftArea.Margin = thicnew; sv.LeftArea.Visibility = Visibility.Collapsed; taShow = null; #region 触发客户端定义的事件 sv.ClosePaneCompletedChanged(); #endregion }; EasingThicknessKeyFrame taFrame = new EasingThicknessKeyFrame(thicnew, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime))); taShow.KeyFrames.Add(taFrame); sv.LeftArea.BeginAnimation(Grid.MarginProperty, taShow); } }
private static void InlineOrOverlayBottom(AySplitView sv, bool isOpenValue) { if (sv.LeftArea.IsNull()) { return; } if (isOpenValue) //从隐藏到显示 { Thickness thickOld = new Thickness(0, 0, 0, sv.LeftArea.Height * (-1)); if (double.IsNaN(sv.OpenPaneLength)) { thickOld = new Thickness(0, 0, 0, sv.cc.RenderSize.Height * (-1)); } sv.LeftArea.Margin = thickOld; sv.LeftArea.Visibility = Visibility.Visible; Thickness thicnew = new Thickness(0, 0, 0, 0); ThicknessAnimationUsingKeyFrames taShow = new ThicknessAnimationUsingKeyFrames(); taShow.Duration = new Duration(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime)); taShow.FillBehavior = FillBehavior.Stop; taShow.Completed += (sender, ev) => { sv.LeftArea.Margin = thicnew; taShow = null; #region 触发客户端定义的事件 sv.OpenPaneCompletedChanged(); #endregion }; EasingThicknessKeyFrame taFrame = new EasingThicknessKeyFrame(thicnew, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime))); taShow.KeyFrames.Add(taFrame); sv.LeftArea.BeginAnimation(Grid.MarginProperty, taShow); } else //显示到隐藏 { Thickness thickOld = new Thickness(0, 0, 0, 0); sv.LeftArea.Margin = thickOld; Thickness thicnew = new Thickness(0, 0, 0, sv.cc.RenderSize.Height * (-1)); if (!double.IsNaN(sv.OpenPaneLength)) { thicnew = new Thickness(0, 0, 0, sv.OpenPaneLength * (-1)); } ThicknessAnimationUsingKeyFrames taShow = new ThicknessAnimationUsingKeyFrames(); taShow.Duration = new Duration(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime)); taShow.FillBehavior = FillBehavior.Stop; taShow.Completed += (sender, ev) => { sv.LeftArea.Margin = thicnew; sv.LeftArea.Visibility = Visibility.Collapsed; taShow = null; #region 触发客户端定义的事件 ====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======盗窃代码请注意========= sv.ClosePaneCompletedChanged(); #endregion }; EasingThicknessKeyFrame taFrame = new EasingThicknessKeyFrame(thicnew, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(sv.OpenMillisecondTime))); taShow.KeyFrames.Add(taFrame); sv.LeftArea.BeginAnimation(Grid.MarginProperty, taShow); } }
/// <summary> 执行方法 </summary> protected override void Invoke(object parameter) { if (this.AssociatedObject == null) { return; } if (this.AutoFindParent) { this.Target = this.AssociatedObject.GetParent <Panel>(); } if (this.Target == null) { this.Target = this.AssociatedObject; } IEnumerable <UIElement> children = null; if (IsUseAll) { children = this.Target.GetChildren <UIElement>().Where(l => l.RenderTransform is TransformGroup); children = children.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4); children = children.Where(l => (l as FrameworkElement)?.Tag?.ToString() != "Except" && !InvokeRandomSplitAnimationAction.GetIsExcept(l)); } else { if (this.Target is Panel panel) { children = panel.Children?.Cast <UIElement>()?.Where(l => l.RenderTransform is TransformGroup); children = children.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4 && !InvokeRandomSplitAnimationAction.GetIsExcept(l)); } } if (children == null) { return; } var controls = children?.ToList(); if (controls == null || controls.Count == 0) { return; } if (this.UseIndex) { controls = this.RandomList(controls); } Storyboard storyboard = new Storyboard(); for (int i = 0; i < controls.Count; i++) { if (this.UseOrigin) { controls[i].RenderTransformOrigin = this.GetRandomOrigin(); } foreach (var item in Timelines.OfType <RandomDoubleAnimation>()) { TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds)); TimeSpan end = item.Duration.TimeSpan + span; DoubleAnimation animation = item.ConvertTo(); if (item.BeginTime == TimeSpan.Zero) { DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame key1 = new EasingDoubleKeyFrame(animation.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero)); frames.KeyFrames.Add(key1); Storyboard.SetTarget(frames, controls[i]); Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item)); storyboard.Children.Add(frames); } animation.BeginTime = span + animation.BeginTime; Storyboard.SetTarget(animation, controls[i]); storyboard.Children.Add(animation); } foreach (var item in Timelines.OfType <ThicknessAnimation>()) { TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds)); TimeSpan end = item.Duration.TimeSpan + span; ThicknessAnimationUsingKeyFrames frames = new ThicknessAnimationUsingKeyFrames(); EasingThicknessKeyFrame key1 = new EasingThicknessKeyFrame(item.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero)); frames.KeyFrames.Add(key1); Storyboard.SetTarget(frames, controls[i]); Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item)); storyboard.Children.Add(frames); ThicknessAnimation animation = item.Clone(); animation.BeginTime = span; Storyboard.SetTarget(animation, controls[i]); storyboard.Children.Add(animation); } } storyboard.FillBehavior = FillBehavior.HoldEnd; storyboard.RepeatBehavior = this.RepeatBehavior; storyboard.Begin(); }
private void AddAnimation() { if (sto == null) { sto = new Storyboard(); ThicknessAnimationUsingKeyFrames thicknessAnimation = new ThicknessAnimationUsingKeyFrames(); thicknessAnimation.AutoReverse = true; thicknessAnimation.RepeatBehavior = RepeatBehavior.Forever; thicknessAnimation.KeyFrames = new ThicknessKeyFrameCollection(); var keyFrame = new EasingThicknessKeyFrame(); keyFrame.Value = new Thickness(1); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)); thicknessAnimation.KeyFrames.Add(keyFrame); Storyboard.SetTarget(thicknessAnimation, border); Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("BorderThickness")); sto.Children.Add(thicknessAnimation); } if (sto2 == null) { var b = border2; sto2 = (Storyboard)border2.Resources["Storyboard2"]; } if (sto3 == null) { txt3.RenderTransformOrigin = new Point(0.5, 0.5); var tfg = new TransformGroup(); tfg.Children.Add(new ScaleTransform()); txt3.RenderTransform = tfg; sto3 = new Storyboard(); DoubleAnimationUsingKeyFrames widthAnimation = new DoubleAnimationUsingKeyFrames(); widthAnimation.AutoReverse = true; widthAnimation.RepeatBehavior = RepeatBehavior.Forever; widthAnimation.KeyFrames = new DoubleKeyFrameCollection(); var widthKeyFrame = new EasingDoubleKeyFrame(); widthKeyFrame.Value = 1.5; widthKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)); widthAnimation.KeyFrames.Add(widthKeyFrame); Storyboard.SetTarget(widthAnimation, txt3); Storyboard.SetTargetProperty(widthAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); DoubleAnimationUsingKeyFrames heightAnimation = new DoubleAnimationUsingKeyFrames(); heightAnimation.AutoReverse = true; heightAnimation.RepeatBehavior = RepeatBehavior.Forever; heightAnimation.KeyFrames = new DoubleKeyFrameCollection(); var heightKeyFrame = new EasingDoubleKeyFrame(); heightKeyFrame.Value = 1.5; heightKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)); heightAnimation.KeyFrames.Add(heightKeyFrame); Storyboard.SetTarget(heightAnimation, txt3); Storyboard.SetTargetProperty(heightAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); sto3.Children.Add(widthAnimation); sto3.Children.Add(heightAnimation); } }