public static void RunScaleAnimation(FrameworkElement e) { var storyboard = new Storyboard(); var easeOut = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.3 }; var startHeight = e.ActualHeight; var startWidth = e.ActualWidth; var growAnimationHOut = new DoubleAnimation(startHeight, startHeight * 1.05, TimeSpan.FromMilliseconds(70)) { AutoReverse = true }; var growAnimationWOut = new DoubleAnimation(startWidth, startWidth * 1.05, TimeSpan.FromMilliseconds(70)) { AutoReverse = true }; growAnimationHOut.EasingFunction = easeOut; growAnimationWOut.EasingFunction = easeOut; storyboard.Children.Add(growAnimationHOut); storyboard.Children.Add(growAnimationWOut); //remove the events after completed to ensure that the ScatterViewItem is resizable again growAnimationWOut.Completed += delegate { e.BeginAnimation(FrameworkElement.WidthProperty, null); }; growAnimationHOut.Completed += delegate { e.BeginAnimation(FrameworkElement.HeightProperty, null); }; Storyboard.SetTargetProperty(growAnimationWOut, new PropertyPath(FrameworkElement.WidthProperty)); Storyboard.SetTargetProperty(growAnimationHOut, new PropertyPath(FrameworkElement.HeightProperty)); e.BeginStoryboard(storyboard); }
static void SlideIn(FrameworkElement frameworkElement) { AnimationTimeline marginAnimation = CreateSlideInAnimation(frameworkElement); frameworkElement.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation); frameworkElement.Visibility = Visibility.Visible; DisableHiddenFrameworkElement(frameworkElement); }
public static void MoveWithRotationAndFadeOut(FrameworkElement element, Point to, double rotationAngle, double seconds, AnimationCompletedDelegate callback) { TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(new RotateTransform(rotationAngle, element.Width / 2, element.Height / 2)); Duration duration = new Duration(TimeSpan.FromSeconds(seconds)); DoubleAnimation animationX = new DoubleAnimation(to.X, duration); DoubleAnimation animationY = new DoubleAnimation(to.Y, duration); DoubleAnimation fadeOutAnimation = new DoubleAnimation { From = 1, To = 0.4, Duration = duration, FillBehavior = FillBehavior.Stop }; animationX.Completed += (sender, _) => callback(sender, _); TranslateTransform trans = new TranslateTransform(); element.RenderTransform = transformGroup; trans.BeginAnimation(TranslateTransform.XProperty, animationX); trans.BeginAnimation(TranslateTransform.YProperty, animationY); element.Opacity = 0.4; element.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation); transformGroup.Children.Add(trans); }
public void AnimatableRootClockConnectionTest() { TestRootClock rootClock = new TestRootClock(); FrameworkElement element = new FrameworkElement(); element.SetAnimatableRootClock(new AnimatableRootClock(rootClock, false)); Assert.AreEqual(0, rootClock.Clocks.Count()); Assert.IsFalse(element.IsVisible); element.IsRootElement = true; Assert.IsTrue(element.IsVisible); DoubleAnimation animation = new DoubleAnimation { From = 0, To = 1 }; element.BeginAnimation(FrameworkElement.WidthProperty, animation); Assert.AreEqual(1, rootClock.Clocks.Count()); rootClock.Tick(TimeSpan.FromSeconds(0.1)); Assert.AreEqual(0.1, element.Width); element.IsRootElement = false; Assert.IsFalse(element.IsVisible); Assert.AreEqual(0, rootClock.Clocks.Count()); rootClock.Tick(TimeSpan.FromSeconds(0.2)); Assert.AreEqual(0.1, element.Width); element.IsRootElement = true; Assert.IsTrue(element.IsVisible); Assert.AreEqual(1, rootClock.Clocks.Count()); Assert.AreEqual(0.2, element.Width); rootClock.Tick(TimeSpan.FromSeconds(2)); Assert.AreEqual(0, rootClock.Clocks.Count()); element.IsRootElement = false; element.IsRootElement = true; Assert.AreEqual(0, rootClock.Clocks.Count()); }
public void FadeOut(FrameworkElement Change) { Change.BeginAnimation(UIElement.OpacityProperty, null); DoubleAnimationUsingKeyFrames opacityAnimation = new DoubleAnimationUsingKeyFrames(); TimeSpan endTime = TimeSpan.FromSeconds(FadeOutDuration); KeyTime kEnd = KeyTime.FromTimeSpan(endTime); opacityAnimation.KeyFrames.Add(new SplineDoubleKeyFrame(FadeOutTo, kEnd)); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("(FrameworkElement.Opacity)")); Storyboard sb = new Storyboard(); sb.BeginTime = TimeSpan.FromMilliseconds(delay); sb.Children.Add(opacityAnimation); sb.Completed += (EventHandler)delegate(object sender, EventArgs e) { Change.Visibility = System.Windows.Visibility.Collapsed; //Change.BeginAnimation(UIElement.OpacityProperty, null); }; sb.Begin(Change); }
public static void animateCollapse(FrameworkElement elem, bool remove) { if (elem.DesiredSize.Height > 0) { elem.Height = elem.DesiredSize.Height; DoubleAnimation pAnimation = createDoubleAnimation(0, 1000, false); pAnimation.FillBehavior = FillBehavior.Stop; pAnimation.Completed += delegate(object sender, EventArgs pEvent) { //elem.BeginAnimation(FrameworkElement.HeightProperty, null); if (remove && elem.Parent is Panel) { ((Panel)elem.Parent).Children.Remove(elem); } else { elem.Visibility = Visibility.Collapsed; elem.Height = Double.NaN; } }; //pAnimation.Freeze(); elem.BeginAnimation(FrameworkElement.HeightProperty, pAnimation, HandoffBehavior.SnapshotAndReplace); } }
public static void ApplyFadeOut(FrameworkElement fe, Duration duration, Duration delay) { if (delay.TimeSpan == TimeSpan.Zero) { DoubleAnimation da = new DoubleAnimation(1.0, 0.0, duration); fe.BeginAnimation(FrameworkElement.OpacityProperty, da); } else { DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); da.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KeyTime.FromTimeSpan(TimeSpan.Zero))); da.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KeyTime.FromTimeSpan(delay.TimeSpan))); da.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(delay.TimeSpan + duration.TimeSpan))); da.Duration = delay + duration; fe.BeginAnimation(FrameworkElement.OpacityProperty, da); } }
/// <summary> /// 初始化整个布局 /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <param name="layout"></param> public static void Initialize(FrameworkElement left, FrameworkElement right, ParentChildProportion leftRightPercent = null) { //layout.AggtBlocks.Layout.ParentChildProportion leftRightPercent = leftRightPercent ?? ParentChildProportion.Default; ResizingPanelExt.SetStarGridLength(left, leftRightPercent.Parent); ResizingPanelExt.SetStarGridLength(right, leftRightPercent.Children); AnimationTimeline show = new DoubleAnimationUsingKeyFrames { KeyFrames = new DoubleKeyFrameCollection() { new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0)) }, new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), Value = leftRightPercent.Children, EasingFunction = new ElasticEase { EasingMode = EasingMode.EaseOut, Springiness = 10 } } } }; AnimationTimeline hide = new DoubleAnimation() { From = leftRightPercent.Children, Duration = new Duration(TimeSpan.FromMilliseconds(100)), To = 0 }; //监听 childrenTab.VisiblityChanged 事件,播放动画效果 DependencyPropertyDescriptor.FromProperty(UIElement.VisibilityProperty, typeof(UIElement)) .AddValueChanged(right, (o, e) => { right.BeginAnimation( ResizingPanelExt.StarGridLengthProperty, right.Visibility == Visibility.Visible ? show : hide ); }); }
private void Animate(FrameworkElement obj, DependencyProperty property, double toValue, Duration duration) { double fromValue = (double)obj.GetValue(property); if (double.IsNaN(fromValue)) fromValue = 0; var animation = new DoubleAnimation(fromValue, toValue, duration, FillBehavior.HoldEnd) { AccelerationRatio = 0.3, DecelerationRatio = 0.3 }; obj.BeginAnimation(property, animation); }
public static void animateSlide(FrameworkElement item, bool reverse = false, bool vertical = true, double movement = 10, double duration = 1) { DoubleAnimation daOpacity = new DoubleAnimation(); DoubleAnimation daMovement = new DoubleAnimation(); if (!reverse) { daOpacity.From = 0; daOpacity.To = 1; daMovement.From = movement; daMovement.To = 0; } else { daOpacity.From = 1; daOpacity.To = 0; daMovement.From = 0; daMovement.To = movement; } daOpacity.Duration = TimeSpan.FromSeconds(duration); daMovement.Duration = TimeSpan.FromSeconds(duration); TranslateTransform tt = new TranslateTransform(); item.RenderTransform = tt; CircleEase ease = new CircleEase(); ease.EasingMode = EasingMode.EaseOut; daOpacity.EasingFunction = ease; daMovement.EasingFunction = ease; item.BeginAnimation(FrameworkElement.OpacityProperty, daOpacity); if (vertical) { tt.BeginAnimation(TranslateTransform.YProperty, daMovement); } else { tt.BeginAnimation(TranslateTransform.XProperty, daMovement); } }
public static void animateFade(FrameworkElement item, double from = 0, double to = 1, double duration = 1) { DoubleAnimation fader = new DoubleAnimation(); fader.From = from; fader.To = to; fader.Duration = TimeSpan.FromSeconds(duration); item.BeginAnimation(FrameworkElement.OpacityProperty, fader); }
private void MoveToNewView(FrameworkElement toViewElement, EventHandler outCompleted, EventHandler inCompleted) { if (_searchThread != null && _searchThread.IsAlive) { _searchThread.Abort(); } var h = this.Height; var durationOut = 0.3; var durationIn = 0.2; ThicknessAnimation animMoveOut = new ThicknessAnimation(); animMoveOut.BeginTime = TimeSpan.FromSeconds(0); animMoveOut.Duration = TimeSpan.FromSeconds(durationOut); animMoveOut.From = new Thickness(0, 0, 0, 0); animMoveOut.To = new Thickness(0, h, 0, -h); animMoveOut.FillBehavior = FillBehavior.Stop; animMoveOut.EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseIn, Exponent = 2 }; animMoveOut.Completed += (s, e) => { _currentViewElement.Visibility = System.Windows.Visibility.Collapsed; if (outCompleted != null) outCompleted(s, e); }; ThicknessAnimation animMoveIn = new ThicknessAnimation(); animMoveIn.BeginTime = TimeSpan.FromSeconds(durationOut + 0.05); animMoveIn.Duration = TimeSpan.FromSeconds(durationIn); animMoveIn.From = new Thickness(0, h, 0, -h); animMoveIn.To = new Thickness(0, 0, 0, 0); animMoveIn.FillBehavior = FillBehavior.Stop; animMoveIn.EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseOut, Exponent = 2 }; animMoveIn.Completed += (s, e) => { _currentViewElement = toViewElement; toViewElement.Margin = new Thickness(0, 0, 0, 0); if (inCompleted != null) inCompleted(s, e); }; toViewElement.Margin = new Thickness(0, h, 0, -h); toViewElement.Visibility = System.Windows.Visibility.Visible; _currentViewElement.BeginAnimation(FrameworkElement.MarginProperty, animMoveOut); toViewElement.BeginAnimation(FrameworkElement.MarginProperty, animMoveIn); }
void AnimateHighlightWidth(FrameworkElement highlightFrameworkElement, DoubleAnimation widthDoubleAnimation) { if (highlightFrameworkElement == null) return; widthDoubleAnimation.From = highlightFrameworkElement.ActualWidth; widthDoubleAnimation.To = SelectedTabHeaderContentWidth; highlightFrameworkElement.BeginAnimation(WidthProperty, widthDoubleAnimation); }
// TODO:움직이기 전 최초 좌표를 설정해줘야함. 지금은 임의로 -500값으로 진행중. // 위쪽에서 등장 private void MoveTTB(FrameworkElement shape) { double x = shape.Margin.Left; double y = shape.Margin.Top; double yMove = 500; PowerEase power = new PowerEase(); ThicknessAnimation linearAnimation = new ThicknessAnimation(); linearAnimation.From = new Thickness(x, y - yMove, 0, 0); linearAnimation.To = new Thickness(x, y, 0, 0); linearAnimation.EasingFunction = power; shape.BeginAnimation(MarginProperty, linearAnimation); }
// 어두워졌다가 밝아져서 형체가 사라진다. private void FadeOut(FrameworkElement shape) { DoubleAnimation fadeOut = new DoubleAnimation(1.0, 0.0, TimeSpan.FromSeconds(1), FillBehavior.HoldEnd); shape.BeginAnimation(OpacityProperty, fadeOut); shape.Visibility = Visibility.Collapsed; }
// 밝아졌다가 형체가 나타난다. private void FadeIn(FrameworkElement shape) { DoubleAnimation fadeIn = new DoubleAnimation(0.0, 1.0, TimeSpan.FromSeconds(1), FillBehavior.HoldEnd); shape.BeginAnimation(OpacityProperty, fadeIn); }
// TODO:움직이기 전 최초 좌표를 설정해줘야함. 지금은 임의로 -500값으로 진행중. // 위쪽에서 등장 private void BoundsTTB(FrameworkElement shape) { double x = shape.Margin.Left; double y = shape.Margin.Top; double yMove = 500; ThicknessAnimation bounceAnimation = new ThicknessAnimation(); BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 4; BounceOrientation.Bounciness = 2; bounceAnimation.From = new Thickness(143, 0, 0, 0); bounceAnimation.From = new Thickness(x, y - yMove, 0, 0); bounceAnimation.To = new Thickness(x, y, 0, 0); bounceAnimation.EasingFunction = BounceOrientation; shape.BeginAnimation(MarginProperty, bounceAnimation); }
/// <summary> /// Detach OpacityProperty of a Frameworkelement from a Storyboard /// </summary> /// <param name="fe">FrameworkElement</param> /// <param name="resetTo">Double</param> public static void DetachOpacityPropertyFromAnimation(FrameworkElement fe, Double resetTo) { fe.BeginAnimation(FrameworkElement.OpacityProperty, null); fe.Opacity = resetTo; }
private void _dispatcherTimer_Tick(object sender, EventArgs e) { _dispatcherTimer.Stop(); if(addedDummyIndex == positionIndex) return; else { if (addedDummyIndex != -1) { Children.RemoveAt(addedDummyIndex); addedDummyIndex = -1; } } if (positionIndex==-1 || positionIndex== addedDummyIndex) return; addedDummyIndex = positionIndex; Children.Insert(positionIndex, _tempNewPositionElement = new Border() { Width = _realDragSource.Width, Height = 0 }); _animation.To = _realDragSource.Height; _tempNewPositionElement.BeginAnimation(HeightProperty, _animation); _expandedCompled = false; }
public void Switch(FrameworkElement ChangeFrom, FrameworkElement ChangeTo) { ChangeFrom.BeginAnimation(UIElement.OpacityProperty, null); ChangeTo.BeginAnimation(UIElement.OpacityProperty, null); FadeOut(ChangeFrom); FadeIn(ChangeTo); }
public static void animateExpand(FrameworkElement elem) { if (elem.ActualHeight < 20) { elem.Height = double.NaN; //auto height elem.Visibility = Visibility.Visible; elem.Measure(new Size(2000,2000)); double height = (elem.DesiredSize.Height > 0) ? elem.DesiredSize.Height : elem.ActualHeight; DoubleAnimation pAnimation = createDoubleAnimation(height, 1000, false); elem.Height = 0; elem.Visibility = Visibility.Visible; pAnimation.FillBehavior = FillBehavior.Stop; pAnimation.Completed += delegate(object sender, EventArgs pEvent) { elem.Height = Double.NaN; //elem.BeginAnimation(FrameworkElement., null); }; //pAnimation.Freeze(); elem.BeginAnimation(FrameworkElement.HeightProperty, pAnimation, HandoffBehavior.SnapshotAndReplace); } }
static void SlideOut(FrameworkElement frameworkElement) { AnimationTimeline marginAnimation = CreateSlideOutAnimation(frameworkElement); frameworkElement.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation); }