public static Timeline CreateDoubleAnimation(this UIElement element, Duration duration, double from, double to, PropertyPath propertyPath, IEasingFunction easingFunction = null) { var animation = new DoubleAnimation(to, duration) { EasingFunction = easingFunction }; if (!double.IsNaN(from)) { animation.From = from; } animation.SetTarget(element).SetTargetProperty(propertyPath); return(animation); }
public void DialogPanelShow(bool bShow) { if (bShow) // force visibility since you can't animate the Visible property { m_this.Visibility = Visibility.Visible; if (m_BackgroundElement != null) m_BackgroundElement.Visibility = Visibility.Visible; } Storyboard storyBoard = new Storyboard(); //j m_this.Resources.Add("SomeSortofKeyName", storyBoard); DoubleAnimation animation = new DoubleAnimation(); animation.From = (bShow ? 0 : 1); animation.To = (bShow ? 1 : 0); animation.Duration = TimeSpan.FromSeconds(0.5); animation.SetTarget(m_RootDialogElement); animation.SetTargetProperty("(UIElement.Opacity)"); storyBoard.Children.Add(animation); if (bShow) storyBoard.Completed += ShowCompleted; else storyBoard.Completed += HideCompleted; storyBoard.Begin(); }
/// <summary> /// /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="millis"></param> /// <param name="easingFunction"></param> /// <param name="target"></param> /// <returns></returns> private static DoubleAnimation GetGenericAnimation(double from, double to, double millis, IEasingFunction easingFunction, UIElement target = null) { DoubleAnimation d = new DoubleAnimation(); d.EasingFunction = easingFunction; d.Duration = TimeSpan.FromMilliseconds(millis); d.From = from; d.To = to; d.SetTarget(target); return d; }