public void Animate(double Before, double After, double Duration, IEasingFunction Easing, DependencyProperty Property, FrameworkElement Item) { Cancel = false; IsCompleted = false; if (Duration == 0 || Before == After) { Item.SetValue(Property, After); return; } this.Before = Before; Item.SetValue(Property, Before); af = After; dp = Property; cnr = Item; Storyboard sb = new Storyboard(); DoubleAnimation da = new DoubleAnimation() { From = Before, To = After, Duration = TimeSpan.FromMilliseconds(Duration), FillBehavior = FillBehavior.Stop, EasingFunction = Easing }; Storyboard.SetTargetProperty(da, new PropertyPath(Property)); sb.Children.Add(da); sb.Completed += Sb_Completed; Item.BeginStoryboard(sb); }
public static void Shaking(this FrameworkElement control) { if (control != null && ShakingStoryboard != null) { if (control is PasswordControl) { ((PasswordControl)control).ShowError(); } else { Transform tran = control.RenderTransform; //TransformGroup group = tran as TransformGroup; if (tran != null && !(tran is TranslateTransform) && tran != Transform.Identity) { throw new Exception("该控件的RenderTransform非TranslateTransform类型。"); } if (tran == null || tran == Transform.Identity) { tran = new TranslateTransform(); control.RenderTransform = tran; } control.BeginStoryboard(ShakingStoryboard); } } }
public void Animate(System.Windows.Thickness Before, System.Windows.Thickness After, int Duration, IEasingFunction Easing, PropertyPath Property, FrameworkElement Item) { if (Before == null || After == null) { return; } if (Duration == 0 || Before == After) { Item.Margin = After; return; } Item.Margin = Before; af = After; cnr = Item; Storyboard sb = new Storyboard(); ThicknessAnimation ta = new ThicknessAnimation() { From = Before, To = After, Duration = TimeSpan.FromMilliseconds(Duration), FillBehavior = FillBehavior.Stop, EasingFunction = Easing }; Storyboard.SetTargetProperty(ta, Property); sb.Children.Add(ta); sb.Completed += Sb_Completed; Item.BeginStoryboard(sb); }
private static void TranslateItem(FrameworkElement f, double yDelta, int milliseconds) { Storyboard sb = (Storyboard)f.GetValue(s_dragPreviewStoryboardProperty); SplineDoubleKeyFrame k; if (sb == null) { TranslateTransform t; DoubleAnimationUsingKeyFrames d; t = new TranslateTransform(); f.RenderTransform = t; sb = new Storyboard(); k = new SplineDoubleKeyFrame(); k.KeySpline = new KeySpline(0, 0.7, 0.7, 1); d = new DoubleAnimationUsingKeyFrames(); d.KeyFrames.Add(k); Storyboard.SetTarget(d, f); Storyboard.SetTargetProperty(d, new PropertyPath("(RenderTransform).(TranslateTransform.Y)")); sb.Children.Add(d); f.SetValue(s_dragPreviewStoryboardProperty, sb); } else { k = (sb.Children[0] as DoubleAnimationUsingKeyFrames).KeyFrames[0] as SplineDoubleKeyFrame; } k.Value = yDelta; k.KeyTime = TimeSpan.FromMilliseconds(milliseconds); f.BeginStoryboard(sb); }
private static void expander_Expanded(object sender, RoutedEventArgs e) { Expander expander = sender as Expander; if (expander != null) { expander.UpdateLayout(); FrameworkElement frameworkElement = (FrameworkElement)expander.Template.FindName("ExpandSite", expander); if (frameworkElement != null) { frameworkElement.Visibility = Visibility.Visible; frameworkElement.UpdateLayout(); Storyboard item = (Storyboard)expander.Template.Resources["Open"]; Storyboard storyboard = (Storyboard)expander.Template.Resources["Close"]; if (storyboard != null) { storyboard.Stop(frameworkElement); } if (item != null) { item.Seek(frameworkElement, new TimeSpan((long)0), TimeSeekOrigin.BeginTime); frameworkElement.BeginStoryboard(item, HandoffBehavior.SnapshotAndReplace, true); } } } }
public void Begin(FrameworkElement element, Action onCompleted) { var storyboard = new Storyboard { Children = { Timeline } }; storyboard.Completed += (s, a) => onCompleted(); element.BeginStoryboard(storyboard); }
private void translate(FrameworkElement element, double from, double to) { DoubleAnimation da = new DoubleAnimation(from, to, new Duration(TimeSpan.FromMilliseconds(500))); Storyboard.SetTargetProperty(da, new PropertyPath("(Canvas.Top)")); //Do not miss the '(' and ')' sb.Children.Add(da); element.BeginStoryboard(sb); }
private static void StartAnimation(Storyboard sb, FrameworkElement control, Action continueWith = null) { var tmp = sb.Clone(); if (continueWith != null) { tmp.Completed += (s, ev) => continueWith(); } control.BeginStoryboard(tmp); }
public static void MarginFadeOutAnimation( this FrameworkElement element, Thickness from, Thickness to, TimeSpan? duration = null, bool useFade = true, bool collapse = true) { if (duration == null) { duration = new TimeSpan(0, 0, 1); } var storyboard = new Storyboard(); storyboard.Completed += (sender, ev) => { if (useFade) { element.Visibility = Visibility.Collapsed; } }; var thicknessAnim = new ThicknessAnimation() { From = from, To = to, Duration = duration.Value, EasingFunction = new QuadraticEase() }; Storyboard.SetTarget(thicknessAnim, element); Storyboard.SetTargetProperty(thicknessAnim, new PropertyPath(FrameworkElement.MarginProperty)); storyboard.Children.Add(thicknessAnim); if (useFade) { var fadeAnim = new DoubleAnimation() { From = 1, To = 0, Duration = duration.Value, EasingFunction = new QuadraticEase() }; Storyboard.SetTarget(fadeAnim, element); Storyboard.SetTargetProperty(fadeAnim, new PropertyPath(UIElement.OpacityProperty)); storyboard.Children.Add(fadeAnim); } element.BeginStoryboard(storyboard); }
/// <summary> /// 在此控件上,执行指定名称的故事板。 /// </summary> /// <param name="control"></param> /// <param name="storyboard_name">故事板的索引,会添加故事板前缀。</param> /// <param name="after_storyboard">在此故事板完成后,要执行的回调。</param> /// <returns>ExecuteAnimationSuccessed 或者 ExecuteUnexistAnimation 之一。</returns> public static int ExecuteStoryboard(this FrameworkElement control, string storyboard_name, EventHandler after_storyboard = null) { var storyboard = SearchStoryboardResource(storyboard_name); if (storyboard == null) { return(ExecuteUnexistAnimation); } if (after_storyboard != null) { storyboard.Completed += after_storyboard; } control.BeginStoryboard(storyboard); return(ExecuteAnimationSuccessed); }
public static bool BeginTransformAnimation(this FrameworkElement targetcontrol, AnimationParameter parameter) { if (targetcontrol != null && parameter != null) { if (targetcontrol.RenderTransform == null || targetcontrol.RenderTransform == Transform.Identity) { targetcontrol.RenderTransform = new TransformGroup { Children = new TransformCollection { new ScaleTransform() { CenterX = parameter.Values.ScaleCenterX, CenterY = parameter.Values.ScaleCenterY, ScaleX = parameter.Values.ScaleFromX, ScaleY = parameter.Values.ScaleFromY }, new TranslateTransform() { X = parameter.Values.TranslateFromX, Y = parameter.Values.TranslateFromY }, new RotateTransform(), new SkewTransform(), } }; } Storyboard storyboard = TransformAnimations.Instance.CreateStoryboard( parameter.ControlAnimation, parameter.Values, parameter.StoryboardComplateCallBack ); if (storyboard != null) { targetcontrol.BeginStoryboard(storyboard); return(true); } } return(false); }
private static void TranslateItem(FrameworkElement element, double delta, int milliseconds, Orientation orientation) { var storyboard = (Storyboard)element.GetValue(_dragPreviewStoryboardProperty); SplineDoubleKeyFrame keyframe; if (storyboard == null) { var t = new TranslateTransform(); element.RenderTransform = t; keyframe = new SplineDoubleKeyFrame { KeySpline = new KeySpline(0, 0.7, 0.7, 1) }; var animation = new DoubleAnimationUsingKeyFrames(); animation.KeyFrames.Add(keyframe); Storyboard.SetTarget(animation, element); PropertyPath propertyPath; if (orientation == Orientation.Vertical) { propertyPath = new PropertyPath("(RenderTransform).(TranslateTransform.Y)"); } else { propertyPath = new PropertyPath("(RenderTransform).(TranslateTransform.X)"); } Storyboard.SetTargetProperty(animation, propertyPath); storyboard = new Storyboard(); storyboard.Children.Add(animation); element.SetValue(_dragPreviewStoryboardProperty, storyboard); } else { keyframe = storyboard.Children.Cast <DoubleAnimationUsingKeyFrames>().Single().KeyFrames.Cast <SplineDoubleKeyFrame>().Single(); } keyframe.Value = delta; keyframe.KeyTime = TimeSpan.FromMilliseconds(milliseconds); element.BeginStoryboard(storyboard); }
private void ShowGrid(FrameworkElement e) { Storyboard storyboard = FindResource("VisibleStoryboard") as Storyboard; e.BeginStoryboard(storyboard); }
private void HideGrid(FrameworkElement e) { Storyboard storyboard = FindResource("CollapsedStoryboard") as Storyboard; e.BeginStoryboard(storyboard); }
/// <summary> /// Begins the animation. /// </summary> public void BeginAnimation() { _fe.BeginStoryboard(sb); }