/// <summary> /// Starts an animation to a particular value on the specified dependency property. /// You can pass in an event handler to call when the animation has completed. /// </summary> /// <param name="pAnimatableElement">The gui element to animate.</param> /// <param name="pDependencyProperty">The dependency property to animate.</param> /// <param name="pToValue">The final value of the dependency property.</param> /// <param name="pAnimationDurationSeconds">The animation duration.</param> /// <param name="pCompletedEvent">The callback executed when the animation ended.</param> public static void StartAnimation(UIElement pAnimatableElement, DependencyProperty pDependencyProperty, double pToValue, double pAnimationDurationSeconds, EventHandler pCompletedEvent) { double lFromValue = (double)pAnimatableElement.GetValue(pDependencyProperty); DoubleAnimation lAnimation = new DoubleAnimation(); lAnimation.From = lFromValue; lAnimation.To = pToValue; lAnimation.Duration = TimeSpan.FromSeconds(pAnimationDurationSeconds); lAnimation.Completed += delegate(object pSender, EventArgs pEventArgs) { // // When the animation has completed bake final value of the animation // into the property. // pAnimatableElement.SetValue(pDependencyProperty, pAnimatableElement.GetValue(pDependencyProperty)); CancelAnimation(pAnimatableElement, pDependencyProperty); if (pCompletedEvent != null) { pCompletedEvent(pSender, pEventArgs); } }; lAnimation.Freeze(); pAnimatableElement.BeginAnimation(pDependencyProperty, lAnimation); }
public static void FadeUIElement(double fromValue, double toValue, UIElement control) { DoubleAnimation da = new DoubleAnimation(fromValue, toValue, time); da.DecelerationRatio = acceleration; da.Completed += UIElementFadeCompleted; control.BeginAnimation(UIElement.OpacityProperty, da); }
/// <summary> /// Starts an animation to a particular value on the specified dependency property. /// You can pass in an event handler to call when the animation has completed. /// </summary> public static void StartAnimation(UIElement animationElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, EventHandler completedEvent) { if (animationElement == null) { throw new ArgumentNullResourceException("animationElement", Resources.General_Given_Parameter_Cannot_Be_Null); } var fromValue = (double)animationElement.GetValue(dependencyProperty); var animation = new DoubleAnimation { From = fromValue, To = toValue, Duration = TimeSpan.FromSeconds(animationDurationSeconds) }; animation.Completed += (sender, e) => { // When the animation has completed bake final value of the animation // into the property. animationElement.SetValue(dependencyProperty, animationElement.GetValue(dependencyProperty)); CancelAnimation(animationElement, dependencyProperty); if (completedEvent != null) { completedEvent(sender, e); } }; animation.Freeze(); animationElement.BeginAnimation(dependencyProperty, animation); }
/// <summary> /// Starts an animation to a particular value on the specified dependency property. /// You can pass in an event handler to call when the animation has completed. /// </summary> public static void StartAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, EventHandler completedEvent) { double fromValue = (double)animatableElement.GetValue(dependencyProperty); DoubleAnimation animation = new DoubleAnimation(); animation.From = fromValue; animation.To = toValue; animation.Duration = TimeSpan.FromSeconds(animationDurationSeconds); animation.Completed += delegate(object sender, EventArgs e) { // // When the animation has completed bake final value of the animation // into the property. // animatableElement.SetValue(dependencyProperty, animatableElement.GetValue(dependencyProperty)); CancelAnimation(animatableElement, dependencyProperty); if (completedEvent != null) { completedEvent(sender, e); } }; animation.Freeze(); animatableElement.BeginAnimation(dependencyProperty, animation); }
/// <summary> /// 控件窗口弹出动画 /// </summary> public static void UIElementCome(UIElement uIElement, ScaleTransform _scale) { PennerDoubleAnimation da = new PennerDoubleAnimation() { From = 0.8, To = 1, Equation = Equations.BackEaseOut, FillBehavior = FillBehavior.Stop, Duration = TimeSpan.FromSeconds(0.5) }; da.Completed += delegate { _scale.ScaleX = 1; _scale.ScaleY = 1; }; DoubleAnimation daO = new DoubleAnimation() { From = 0, To = 1, FillBehavior = FillBehavior.Stop, Duration = TimeSpan.FromSeconds(0.7) }; daO.Completed += delegate { uIElement.Opacity = 1; }; _scale.BeginAnimation(ScaleTransform.ScaleXProperty, da); _scale.BeginAnimation(ScaleTransform.ScaleYProperty, da); uIElement.BeginAnimation(UIElement.OpacityProperty, daO); }
public static void Animate(UIElement element, DependencyProperty property, double toValue, double duration) { DoubleAnimation Animation = new DoubleAnimation(); Animation.To = toValue; Animation.Duration = new Duration(TimeSpan.FromSeconds(duration)); element.BeginAnimation(property, Animation); }
public static void fadeIn(UIElement itemToBeAnimated, double animationTimeInSeconds) { DoubleAnimation da = new DoubleAnimation(); da.From = 0; da.To = 1; da.Duration = new Duration(TimeSpan.FromSeconds(animationTimeInSeconds)); itemToBeAnimated.BeginAnimation(OpacityProperty, da); }
/// <summary> /// Cancel any animations that are running on the specified dependency property. /// </summary> public static void CancelAnimation(UIElement animatedElement, DependencyProperty dependencyProperty) { if (animatedElement == null) { throw new ArgumentNullResourceException("animatedElement", Resources.General_Given_Parameter_Cannot_Be_Null); } animatedElement.BeginAnimation(dependencyProperty, null); }
public static void HideAndFadeOut(UIElement control, double seconds) { DoubleAnimation fadeout = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(seconds))); fadeout.Completed += delegate(object sender,EventArgs e) { control.Visibility = Visibility.Collapsed; }; control.BeginAnimation(UIElement.OpacityProperty, fadeout); }
public static void fadeInOut(UIElement itemToBeAnimated, double animationTimeInSeconds, int timesRepeated) { DoubleAnimation da = new DoubleAnimation(); da.From = 1; da.To = 0; da.Duration = new Duration(TimeSpan.FromSeconds(animationTimeInSeconds)); da.AutoReverse = true; da.RepeatBehavior = new RepeatBehavior(timesRepeated); itemToBeAnimated.BeginAnimation(OpacityProperty, da); }
public void Start(object source) { //WPF objects MUST be created on the goddamn dispatcher thread, otherwise you run into trouble makeVisible = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromSeconds(Duration))); makeInvisible = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(Duration))); openingSource = source as UIElement; if (openingSource == null) return; openingSource.BeginAnimation(UIElement.OpacityProperty, makeVisible); }
public static void StartAnimation (UIElement animatableElement, DependencyProperty dependencyProperty, double toValue, double durationMilliseconds, double accelerationRatio, double decelerationRatio) { DoubleAnimation animation = new DoubleAnimation(); animation.To = toValue; animation.AccelerationRatio = accelerationRatio; animation.DecelerationRatio = decelerationRatio; animation.FillBehavior = FillBehavior.HoldEnd; animation.Duration = TimeSpan.FromMilliseconds(durationMilliseconds); animation.Freeze(); animatableElement.BeginAnimation(dependencyProperty, animation, HandoffBehavior.Compose); }
public static void DoMove(UIElement uie, DependencyProperty dp, double to, double ar, double dr, double duration) { var doubleAnimation = new DoubleAnimation { To = to, Duration = TimeSpan.FromSeconds(duration), AccelerationRatio = ar, DecelerationRatio = dr, FillBehavior = FillBehavior.HoldEnd };//创建双精度动画对象 uie.BeginAnimation(dp, doubleAnimation);//设置动画应用的属性并启动动画 }
public static void AddChildSP(UIElement child, StackPanel sp, int start_time) { sp.Children.Add(child); child.Opacity = 0.0; DoubleAnimation an = new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(200)); an.BeginTime = TimeSpan.FromMilliseconds(start_time += 80); child.BeginAnimation(btnDugmeTemp.OpacityProperty, an); DoubleAnimation da = new DoubleAnimation(50, 0, new Duration(TimeSpan.FromMilliseconds(200))); da.BeginTime = TimeSpan.FromMilliseconds(start_time); da.DecelerationRatio = 0.7; TranslateTransform rt = new TranslateTransform(); child.RenderTransform = rt; rt.BeginAnimation(TranslateTransform.XProperty, da); }
protected override Point ProcessNewChild(UIElement child, Rect providedBounds) { var startLocation = providedBounds.Location; if (m_arrangedOnce) { if (m_itemOpacityAnimation == null) { m_itemOpacityAnimation = new DoubleAnimation() { From = 0, Duration = new Duration(TimeSpan.FromSeconds(.5)) }; m_itemOpacityAnimation.Freeze(); } child.BeginAnimation(UIElement.OpacityProperty, m_itemOpacityAnimation); startLocation -= new Vector(providedBounds.Width, 0); } return startLocation; }
/// <summary> /// Cancel any animations that are running on the specified dependency property. /// </summary> public static void CancelAnimation(UIElement animatableElement, DependencyProperty dependencyProperty) { animatableElement.BeginAnimation(dependencyProperty, null); }
/// <summary> /// Animates the opacity of the specified object. /// </summary> /// <param name="obj"> /// The object to animate. /// </param> /// <param name="toOpacity"> /// The to opacity. /// </param> /// <param name="animationTime"> /// The animation time. /// </param> private static void AnimateOpacity(UIElement obj, double toOpacity, double animationTime) { var a = new DoubleAnimation(toOpacity, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5 }; obj.BeginAnimation(OpacityProperty, a); }
public void AddItem(UIElement item) { Util.RequireNotNull(item, "item"); Util.RequireArgument(VisualTreeHelper.GetParent(item) == null, "item", "item should not have a parent"); m_elements.Add(item); this.AddVisualChild(item); this.InvalidateMeasure(); item.RenderTransformOrigin = new Point(.5, .5); TransformGroup group = new TransformGroup(); group.Children.Add(new ScaleTransform(.6, .6)); ScaleTransform animatedScale = new ScaleTransform(); group.Children.Add(animatedScale); RotateTransform rotateTransform = new RotateTransform(); group.Children.Add(rotateTransform); group.Children.Add(new TranslateTransform()); item.RenderTransform = group; if (m_elements.Count >= c_maxCount) { int oldestCount = m_elements.Count - c_maxCount; for (int i = 0; i < oldestCount; i++) { UIElement oldest = m_elements[0]; m_fadingElements.Add(oldest); m_elements.RemoveAt(0); DoubleAnimation fadeOut = GetFadeOutAnimation(); fadeOut.Completed += delegate(object sender, EventArgs e) { m_fadingElements.Remove(oldest); this.RemoveVisualChild(oldest); }; oldest.BeginAnimation(UIElement.OpacityProperty, fadeOut); } } DoubleAnimation rotationAnimation = GetRandomRotateAnimation(); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, rotationAnimation); DoubleAnimation fadeIn = GetFadeInAnimation(); item.BeginAnimation(UIElement.OpacityProperty, fadeIn); DoubleAnimation shrink = GetShrinkAnimation(); animatedScale.BeginAnimation(ScaleTransform.ScaleXProperty, shrink); animatedScale.BeginAnimation(ScaleTransform.ScaleYProperty, shrink); }
private void ProcessDeleteGridItem(UIElement itemControl) { var animation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.01))); animation.BeginTime = TimeSpan.FromSeconds(0.09); itemControl.BeginAnimation(UIElement.OpacityProperty, animation); }
private void ChangeContent(UIElement newContent) { if (transitionHolder.Children.Count == 0) { transitionHolder.Children.Add(newContent); return; } if (transitionHolder.Children.Count == 1) { transitionHolder.IsHitTestVisible = false; UIElement oldContent = transitionHolder.Children[0]; // An anoynmous function....interesting EventHandler onAnimationCompletedHandler = delegate(object sender, EventArgs e) { transitionHolder.IsHitTestVisible = true; transitionHolder.Children.Remove(oldContent); // All these have destroyInternals on them ideally would have extended // a common class to not have to do all this casting try { SectionAttract att = oldContent as SectionAttract; if (att != null) { destroyAttractSection(false); } SectionPhoto phot = oldContent as SectionPhoto; if (phot != null) { destroyPhotoSection(false); } } catch (Exception ex) { // Who cares Console.WriteLine("Animation Helper Exception destroying internals on one of the main sections - " + ex.ToString()); } }; // ---- SLide animation ----- double leftStart = Canvas.GetLeft(oldContent); Canvas.SetLeft(newContent, leftStart - GlobalConfiguration.currentScreenW); transitionHolder.Children.Add(newContent); if (double.IsNaN(leftStart)) { leftStart = 0; } // -----> WHERE IS WIDTH COMING FROM??? THE WINDOW?? DoubleAnimation outAnimation = new DoubleAnimation(leftStart, leftStart + GlobalConfiguration.currentScreenW, new Duration(TimeSpan.FromSeconds(0.5))); DoubleAnimation inAnimation = new DoubleAnimation(leftStart - GlobalConfiguration.currentScreenW, leftStart, new Duration(TimeSpan.FromSeconds(0.5))); inAnimation.Completed += onAnimationCompletedHandler; // Easing SineEase ease = new SineEase(); ease.EasingMode = EasingMode.EaseOut; outAnimation.EasingFunction = ease; inAnimation.EasingFunction = ease; oldContent.BeginAnimation(Canvas.LeftProperty, outAnimation); newContent.BeginAnimation(Canvas.LeftProperty, inAnimation); } }
/// <summary> /// Causes the specified element to begin fading out. /// </summary> /// <param name="element"></param> private static void HideElement(UIElement element) { // get the initial opacity double fromOpacity = element.Opacity; // cancel any previous animation element.BeginAnimation(UIElement.OpacityProperty, null); // start our new animation DoubleAnimation fadeOut = new DoubleAnimation( fromOpacity, 0.0, new Duration(TimeSpan.FromMilliseconds(200)), FillBehavior.HoldEnd); fadeOut.Completed += delegate(object sender, EventArgs e) { element.Visibility = Visibility.Hidden; }; element.BeginAnimation(UIElement.OpacityProperty, fadeOut); }
private void ProcessNewCreatedGridItem(UIElement itemControl) { itemControl.RenderTransformOrigin = new Point(0.5, 0.5); var scaleTransform = new ScaleTransform(0, 0); itemControl.RenderTransform = scaleTransform; //itemControl.SetValue(UIElement.OpacityProperty, 0); var opacityAnimation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(0.08))); itemControl.BeginAnimation(UIElement.OpacityProperty, opacityAnimation); var animation = CreateRenderScaleAnimation(); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, animation); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, animation); }
public static void SlideDown(UIElement elem) { int vremeTrajanjaAnim = 500; DoubleAnimation animacijaTrans = new DoubleAnimation(0, System.Windows.SystemParameters.PrimaryScreenHeight, TimeSpan.FromMilliseconds(vremeTrajanjaAnim)); DoubleAnimation animacijaProv = new DoubleAnimation(1, 0.3, TimeSpan.FromMilliseconds(vremeTrajanjaAnim)); ExponentialEase easing = new ExponentialEase(); easing.EasingMode = EasingMode.EaseIn; easing.Exponent = 8; animacijaTrans.EasingFunction = easing; animacijaProv.EasingFunction = easing; animacijaTrans.Completed += (o, eventArg) => { if (elem is TastaturaXAML) { (elem as TastaturaXAML).Close(); } if (elem is Page) { (elem as Page).NavigationService.GoBack(); } }; TranslateTransform translacija = new TranslateTransform(); elem.RenderTransformOrigin = new Point(System.Windows.SystemParameters.PrimaryScreenHeight, 0); elem.RenderTransform = translacija; translacija.BeginAnimation(TranslateTransform.YProperty, animacijaTrans); if(elem is UIElement) elem.BeginAnimation(UIElement.OpacityProperty, animacijaProv); if (elem is Page) elem.BeginAnimation(Page.OpacityProperty, animacijaProv); }
public static void SlideUp(UIElement elem) { int start_time = 500; ExponentialEase easing = new ExponentialEase(); easing.EasingMode = EasingMode.EaseOut; easing.Exponent = 8; DoubleAnimation daaa = new DoubleAnimation(0.3, 1, TimeSpan.FromMilliseconds(start_time)); elem.BeginAnimation(UIElement.OpacityProperty, daaa); DoubleAnimation daa = new DoubleAnimation(System.Windows.SystemParameters.PrimaryScreenHeight, 0, TimeSpan.FromMilliseconds(start_time)); daa.EasingFunction = easing; TranslateTransform tt = new TranslateTransform(); elem.RenderTransformOrigin = new Point(System.Windows.SystemParameters.PrimaryScreenHeight, 0); elem.RenderTransform = tt; tt.BeginAnimation(TranslateTransform.YProperty, daa); }
public static void RemoveChildAnimate(UIElement child, Grid grid) { int start_time = 100; DoubleAnimation an = new DoubleAnimation(1.0, 0, TimeSpan.FromMilliseconds(start_time)); child.BeginAnimation(btnDugmeTemp.OpacityProperty, an); DoubleAnimation da = new DoubleAnimation(1.0, 0, TimeSpan.FromMilliseconds(start_time)); da.Completed += (object sender, EventArgs e) => { grid.Children.Remove(child); }; ScaleTransform rt = new ScaleTransform(); child.RenderTransformOrigin = new Point(0.5, 0.5); child.RenderTransform = rt; rt.BeginAnimation(ScaleTransform.ScaleXProperty, da); rt.BeginAnimation(ScaleTransform.ScaleYProperty, da); }
private void ProcessMoveGridItem(UIElement itemControl, GridViewModel gridViewModel, double itemWidth, double itemHeight) { GridMoveInfo moveInfo = gridViewModel.MoveInfo; if (moveInfo.FromCol != moveInfo.ToCol) { itemControl.BeginAnimation( Canvas.LeftProperty, CreateMoveAnimation(moveInfo.FromCol * itemWidth, moveInfo.ToCol * itemWidth)); } else { Canvas.SetLeft(itemControl, moveInfo.ToCol * itemWidth); } if (moveInfo.FromRow != moveInfo.ToRow) { itemControl.BeginAnimation( Canvas.TopProperty, CreateMoveAnimation(moveInfo.FromRow * itemHeight, moveInfo.ToRow * itemHeight)); } else { Canvas.SetTop(itemControl, moveInfo.ToRow * itemHeight); } }
/// <summary> /// Fades the specified element. /// </summary> /// <param name="element">The element.</param> /// <param name="from">The value to be faded from.</param> /// <param name="to">The value to be faded to.</param> /// <param name="time">The time value.</param> /// <param name="whenDone">The when done.</param> public static void Fade(UIElement element, double from, double to, double time, EventHandler whenDone = null) { element.BeginAnimation(UIElement.OpacityProperty, CreateDoubleAnimation(from, to, time, null, whenDone)); }
public static void BeginAnimationOpacity(this UIElement element, double to, double duration = 1000) { DoubleAnimation xd = new DoubleAnimation(to, TimeSpan.FromMilliseconds(duration)); element.BeginAnimation(UIElement.OpacityProperty, xd); }
public static void Fade_In_Control(UIElement c, int seconds) { Duration dur = new Duration(new TimeSpan(0, 0, 0, 0, seconds)); fadeIn.Duration = dur; c.BeginAnimation(Control.OpacityProperty, fadeIn); }
/// <summary> /// Causes the specified element to begin fading in. /// </summary> /// <param name="element"></param> private static void ShowElement(UIElement element) { if (element.Visibility != Visibility.Visible) { element.Opacity = 0; element.Visibility = Visibility.Visible; } // get the initial opacity double fromOpacity = element.Opacity; // cancel any previous animation element.BeginAnimation(UIElement.OpacityProperty, null); // start our new animation element.Opacity = 1.0; DoubleAnimation fadeIn = new DoubleAnimation( fromOpacity, 1.0, new Duration(TimeSpan.FromMilliseconds(200)), FillBehavior.Stop); fadeIn.Completed += delegate(object sender, EventArgs e) { element.Visibility = Visibility.Visible; }; element.BeginAnimation(UIElement.OpacityProperty, fadeIn); }
/// <summary> /// Cancel any animations that are running on the specified dependency property. /// </summary> public static void CancelAnimation(UIElement animatableElement, DependencyProperty dependencyProperty) { #if !SILVERLIGHT animatableElement.BeginAnimation(dependencyProperty, null); #endif }