public static Storyboard CreateDoubleSB(DependencyObject dpnObj, string property, double secondTime, Double from, Double to, EasingMode em) { //<Storyboard x:Name="Storyboard1"> // <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="border"> // <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/> // </DoubleAnimationUsingKeyFrames> //</Storyboard> DoubleAnimationUsingKeyFrames daKeyFrame = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame edKeyFrame = new EasingDoubleKeyFrame(); edKeyFrame.KeyTime = TimeSpan.FromSeconds(secondTime); edKeyFrame.Value = to; CircleEase ce = new CircleEase(); ce.EasingMode = em; edKeyFrame.EasingFunction = ce; daKeyFrame.KeyFrames.Add(edKeyFrame); daKeyFrame.EnableDependentAnimation = true; Storyboard.SetTarget(daKeyFrame, dpnObj); Storyboard.SetTargetProperty(daKeyFrame, property); Storyboard sb = new Storyboard(); sb.Children.Add(daKeyFrame); return sb; }
public static Storyboard CreateSizeAnimation( this Storyboard sb, FrameworkElement target, Size start, Size end, double timeSecs = 1.0, double delay = 0) { if (sb == null) throw new NullReferenceException("The storyboard could not be Null"); DoubleAnimationUsingKeyFrames animH = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames animW = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame d1; EasingDoubleKeyFrame d2; //Creating Hight Frames d1 = new EasingDoubleKeyFrame(); d1.Value = start.Height; d1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay)); d2 = new EasingDoubleKeyFrame(); d2.Value = end.Height; d2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay+timeSecs)); animH.KeyFrames.Add(d1); animH.KeyFrames.Add(d2); animH.EnableDependentAnimation = true; ////////////////////////////////////// //Creating Width Frames d1 = new EasingDoubleKeyFrame(); d1.Value = start.Width; d1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay)); d2 = new EasingDoubleKeyFrame(); d2.Value = end.Width; d2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay+timeSecs)); animW.KeyFrames.Add(d1); animW.KeyFrames.Add(d2); animW.EnableDependentAnimation = true; ////////////////////////////////////// sb.Children.Add(animH); sb.Children.Add(animW); Storyboard.SetTarget(animH, target); Storyboard.SetTarget(animW, target); Storyboard.SetTargetProperty(animH, "(FrameworkElement.Height)"); Storyboard.SetTargetProperty(animW, "(FrameworkElement.Width)"); sb.SetStoryboardDuration(new Duration(TimeSpan.FromSeconds(delay + timeSecs))); return sb; }
private void Init() { _Storyboard = new Storyboard(); _Storyboard.Completed += _Storyboard_Completed; /***animation x***/ _Animation_X = new DoubleAnimationUsingKeyFrames(); /*key frame x from*/ _KeyFrame_x_from = new EasingDoubleKeyFrame(); _KeyFrame_x_from.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); _KeyFrame_x_from.Value = 0; _Animation_X.KeyFrames.Add(_KeyFrame_x_from); /*key frame x to*/ _KeyFrame_x_to = new EasingDoubleKeyFrame(); _KeyFrame_x_to.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); _KeyFrame_x_to.Value = 1; _Animation_X.KeyFrames.Add(_KeyFrame_x_to); Storyboard.SetTargetProperty(_Animation_X, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)"); _Storyboard.Children.Add(_Animation_X); /***animation y***/ _Animation_Y = new DoubleAnimationUsingKeyFrames(); /*key frame 1*/ _KeyFrame_y_from = new EasingDoubleKeyFrame(); _KeyFrame_y_from.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); _KeyFrame_y_from.Value = 0; _Animation_Y.KeyFrames.Add(_KeyFrame_y_from); /*key frame 2*/ _KeyFrame_y_to = new EasingDoubleKeyFrame(); _KeyFrame_y_to.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)); _KeyFrame_y_to.Value = 1; _Animation_Y.KeyFrames.Add(_KeyFrame_y_to); Storyboard.SetTargetProperty(_Animation_Y, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)"); _Storyboard.Children.Add(_Animation_Y); }
private void Init() { _Storyboard = new Storyboard(); _Storyboard.Completed += _Storyboard_Completed; /***animation ***/ _Animation = new DoubleAnimationUsingKeyFrames(); /*key frame from*/ _KeyFrame_from = new EasingDoubleKeyFrame(); _KeyFrame_from.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); _KeyFrame_from.Value = 0; _Animation.KeyFrames.Add(_KeyFrame_from); /*key frame to*/ _KeyFrame_to = new EasingDoubleKeyFrame(); _KeyFrame_to.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)); _KeyFrame_to.Value = 1; _Animation.KeyFrames.Add(_KeyFrame_to); Storyboard.SetTargetProperty(_Animation, "(UIElement.RenderTransform).(CompositeTransform.Rotation)"); _Storyboard.Children.Add(_Animation); }
private void Init() { _Storyboard = new Storyboard(); _Storyboard.Completed += _Storyboard_Completed; /***animation x***/ _Animation = new DoubleAnimationUsingKeyFrames(); /*key frame 1*/ _KeyFrame_from = new EasingDoubleKeyFrame(); _KeyFrame_from.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); _KeyFrame_from.Value = 0; _Animation.KeyFrames.Add(_KeyFrame_from); /*key frame 2*/ _KeyFrame_to = new EasingDoubleKeyFrame(); _KeyFrame_to.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)); _KeyFrame_to.Value = 0; _Animation.KeyFrames.Add(_KeyFrame_to); Storyboard.SetTargetProperty(_Animation, "(UIElement.Opacity)"); _Storyboard.Children.Add(_Animation); }
public static Storyboard CreateFadIn( this Storyboard sb, UIElement target, double from, double to, double timeSecs = 1.0, double delay = 0) { if (sb == null) throw new NullReferenceException("The storyboard could not be Null"); DoubleAnimationUsingKeyFrames animA = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame d1; EasingDoubleKeyFrame d2; d1 = new EasingDoubleKeyFrame(); d1.Value = from; d1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay)); d2 = new EasingDoubleKeyFrame(); d2.Value = to; d2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay + timeSecs)); animA.KeyFrames.Add(d1); animA.KeyFrames.Add(d2); animA.EnableDependentAnimation = true; sb.Children.Add(animA); Storyboard.SetTarget(animA, target); Storyboard.SetTargetProperty(animA, UI_ELEMENT_OPACITY); sb.SetStoryboardDuration(new Duration(TimeSpan.FromSeconds(delay + timeSecs))); return sb; }
public static Storyboard MakeOpacityStory(DependencyObject element, double fromValue, double toValue, TimeSpan lastTime) { Storyboard sb = new Storyboard(); DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(frames, "Opacity"); Storyboard.SetTarget(frames, element); EasingDoubleKeyFrame frame1 = new EasingDoubleKeyFrame(); frame1.KeyTime = new TimeSpan(0, 0, 0, 0); frame1.Value = fromValue; EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame(); frame2.KeyTime = lastTime; frame2.Value = toValue; frames.KeyFrames.Add(frame1); frames.KeyFrames.Add(frame2); sb.FillBehavior = FillBehavior.HoldEnd; sb.Children.Add(frames); return sb; }
protected override void OnApplyTemplate() { if (_touchAreaRectangle != null) { _touchAreaRectangle.Tapped -= OnTouchAreaRectangleTap; } base.OnApplyTemplate(); _touchAreaRectangle = GetTemplateChild(TouchAreaRectangle) as Rectangle; _expandedToCollapsedFrame = GetTemplateChild(ExpandedToCollapsedKeyFrame) as EasingDoubleKeyFrame; _collapsedToExpandedFrame = GetTemplateChild(CollapsedToExpandedKeyFrame) as EasingDoubleKeyFrame; _itemsCanvas = GetTemplateChild("ItemsCanvas") as Canvas; _header = GetTemplateChild("ExpandableContent") as Border; var expandedState = (GetTemplateChild(ExpandedState) as VisualState); if (expandedState != null) { _expandedStateAnimation = expandedState.Storyboard.Children[0] as DoubleAnimation; } _presenter = GetTemplateChild(Presenter) as ItemsPresenter; if (_presenter != null) { _presenter.SizeChanged += OnPresenterSizeChanged; } if (_touchAreaRectangle != null) { _touchAreaRectangle.Tapped += OnTouchAreaRectangleTap; } if (_itemsCanvas != null) { _itemsCanvas.SizeChanged += OnPresenterSizeChanged; } UpdateVisualState(false); }
internal void AnimateContainerDropDown() { if (Items == null) return; for (var i = 0; i < Items.Count; i++) { var container = ContainerFromIndex(i) as FrameworkElement; if (container == null) { break; } var itemDropDown = new Storyboard(); var quadraticEase = new QuadraticEase { EasingMode = EasingMode.EaseOut }; var initialKeyTime = InitialKeyTime + (KeyTimeStep * i); var finalKeyTime = FinalKeyTime + (KeyTimeStep * i); var translation = new TranslateTransform(); container.RenderTransform = translation; var transAnimation = new DoubleAnimationUsingKeyFrames(); var transKeyFrame1 = new EasingDoubleKeyFrame { EasingFunction = quadraticEase, KeyTime = TimeSpan.FromMilliseconds(0.0), Value = -150.0 }; var transKeyFrame2 = new EasingDoubleKeyFrame { EasingFunction = quadraticEase, KeyTime = TimeSpan.FromMilliseconds(initialKeyTime), Value = 0.0 }; var transKeyFrame3 = new EasingDoubleKeyFrame { EasingFunction = quadraticEase, KeyTime = TimeSpan.FromMilliseconds(finalKeyTime), Value = 0.0 }; transAnimation.KeyFrames.Add(transKeyFrame1); transAnimation.KeyFrames.Add(transKeyFrame2); transAnimation.KeyFrames.Add(transKeyFrame3); Storyboard.SetTarget(transAnimation, container); Storyboard.SetTargetProperty(transAnimation, "(UIElement.RenderTransform).(TranslateTransform.Y)"); itemDropDown.Children.Add(transAnimation); var opacityAnimation = new DoubleAnimationUsingKeyFrames(); var opacityKeyFrame1 = new EasingDoubleKeyFrame { EasingFunction = quadraticEase, KeyTime = TimeSpan.FromMilliseconds(0.0), Value = 0.0 }; var opacityKeyFrame2 = new EasingDoubleKeyFrame { EasingFunction = quadraticEase, KeyTime = TimeSpan.FromMilliseconds(initialKeyTime - 150), Value = 0.0 }; var opacityKeyFrame3 = new EasingDoubleKeyFrame { EasingFunction = quadraticEase, KeyTime = TimeSpan.FromMilliseconds(finalKeyTime), Value = 1.0 }; opacityAnimation.KeyFrames.Add(opacityKeyFrame1); opacityAnimation.KeyFrames.Add(opacityKeyFrame2); opacityAnimation.KeyFrames.Add(opacityKeyFrame3); Storyboard.SetTarget(opacityAnimation, container); Storyboard.SetTargetProperty(opacityAnimation, "(UIElement.Opacity)"); itemDropDown.Children.Add(opacityAnimation); itemDropDown.Begin(); } }
public override void PlayReverse(Action completed) { var storyboard = new Storyboard(); var toPage = ToPage; var scaleTransform = new ScaleTransform { CenterX = ToPage.ActualWidth/2, CenterY = ToPage.ActualHeight/2, ScaleX = 1, ScaleY = 1 }; toPage.RenderTransform = scaleTransform; ToPage.Opacity = 1; storyboard.Duration = new Duration(TimeSpan.FromSeconds(0.15)); var doubleAnimationUsingKeyFrame = new DoubleAnimationUsingKeyFrames { RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)), FillBehavior = FillBehavior.HoldEnd }; var doubleAnimationUsingKeyFrame1 = doubleAnimationUsingKeyFrame; var keyFrames = doubleAnimationUsingKeyFrame1.KeyFrames; var easingDoubleKeyFrame = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 1, EasingFunction = new CubicEase() }; keyFrames.Add(easingDoubleKeyFrame); var doubleKeyFrameCollection = doubleAnimationUsingKeyFrame1.KeyFrames; var easingDoubleKeyFrame1 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)), Value = 1.4, EasingFunction = new CubicEase() }; doubleKeyFrameCollection.Add(easingDoubleKeyFrame1); Storyboard.SetTarget(doubleAnimationUsingKeyFrame1, ToPage); Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame1, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)"); storyboard.Children.Add(doubleAnimationUsingKeyFrame1); var doubleAnimationUsingKeyFrame2 = new DoubleAnimationUsingKeyFrames { RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)), FillBehavior = FillBehavior.HoldEnd }; var doubleAnimationUsingKeyFrame3 = doubleAnimationUsingKeyFrame2; var keyFrames1 = doubleAnimationUsingKeyFrame3.KeyFrames; var easingDoubleKeyFrame2 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 1, EasingFunction = new CubicEase() }; keyFrames1.Add(easingDoubleKeyFrame2); var doubleKeyFrameCollection1 = doubleAnimationUsingKeyFrame3.KeyFrames; var easingDoubleKeyFrame3 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)), Value = 1.4, EasingFunction = new CubicEase() }; doubleKeyFrameCollection1.Add(easingDoubleKeyFrame3); Storyboard.SetTarget(doubleAnimationUsingKeyFrame3, ToPage); Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame3, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)"); storyboard.Children.Add(doubleAnimationUsingKeyFrame3); var doubleAnimationUsingKeyFrame4 = new DoubleAnimationUsingKeyFrames { RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)), FillBehavior = FillBehavior.HoldEnd }; var doubleAnimationUsingKeyFrame5 = doubleAnimationUsingKeyFrame4; var keyFrames2 = doubleAnimationUsingKeyFrame5.KeyFrames; var easingDoubleKeyFrame4 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 1, EasingFunction = new CubicEase() }; keyFrames2.Add(easingDoubleKeyFrame4); var doubleKeyFrameCollection2 = doubleAnimationUsingKeyFrame5.KeyFrames; var easingDoubleKeyFrame5 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)), Value = 0, EasingFunction = new CubicEase() }; doubleKeyFrameCollection2.Add(easingDoubleKeyFrame5); Storyboard.SetTarget(doubleAnimationUsingKeyFrame5, ToPage); Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame5, "(UIElement.Opacity)"); storyboard.Children.Add(doubleAnimationUsingKeyFrame5); var fromPage = FromPage; var scaleTransform1 = new ScaleTransform { CenterX = FromPage.ActualWidth/2, CenterY = FromPage.ActualHeight/2, ScaleX = 1, ScaleY = 1 }; fromPage.RenderTransform = scaleTransform1; FromPage.Opacity = 1; var doubleAnimationUsingKeyFrame6 = new DoubleAnimationUsingKeyFrames { RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)), FillBehavior = FillBehavior.HoldEnd }; var doubleAnimationUsingKeyFrame7 = doubleAnimationUsingKeyFrame6; var keyFrames3 = doubleAnimationUsingKeyFrame7.KeyFrames; var easingDoubleKeyFrame6 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0.3, EasingFunction = new SineEase() }; keyFrames3.Add(easingDoubleKeyFrame6); var doubleKeyFrameCollection3 = doubleAnimationUsingKeyFrame7.KeyFrames; var easingDoubleKeyFrame7 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)), Value = 1, EasingFunction = new SineEase() }; doubleKeyFrameCollection3.Add(easingDoubleKeyFrame7); Storyboard.SetTarget(doubleAnimationUsingKeyFrame7, FromPage); Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame7, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)"); storyboard.Children.Add(doubleAnimationUsingKeyFrame7); var doubleAnimationUsingKeyFrame8 = new DoubleAnimationUsingKeyFrames { RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)), FillBehavior = FillBehavior.HoldEnd }; var doubleAnimationUsingKeyFrame9 = doubleAnimationUsingKeyFrame8; var keyFrames4 = doubleAnimationUsingKeyFrame9.KeyFrames; var easingDoubleKeyFrame8 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0.3, EasingFunction = new SineEase() }; keyFrames4.Add(easingDoubleKeyFrame8); var doubleKeyFrameCollection4 = doubleAnimationUsingKeyFrame9.KeyFrames; var easingDoubleKeyFrame9 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)), Value = 1, EasingFunction = new SineEase() }; doubleKeyFrameCollection4.Add(easingDoubleKeyFrame9); Storyboard.SetTarget(doubleAnimationUsingKeyFrame9, FromPage); Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame9, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)"); storyboard.Children.Add(doubleAnimationUsingKeyFrame9); var doubleAnimationUsingKeyFrame10 = new DoubleAnimationUsingKeyFrames { RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)), FillBehavior = FillBehavior.HoldEnd }; var doubleAnimationUsingKeyFrame11 = doubleAnimationUsingKeyFrame10; var keyFrames5 = doubleAnimationUsingKeyFrame11.KeyFrames; var easingDoubleKeyFrame10 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0, EasingFunction = new SineEase() }; keyFrames5.Add(easingDoubleKeyFrame10); var doubleKeyFrameCollection5 = doubleAnimationUsingKeyFrame11.KeyFrames; var easingDoubleKeyFrame11 = new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)), Value = 1, EasingFunction = new SineEase() }; doubleKeyFrameCollection5.Add(easingDoubleKeyFrame11); Storyboard.SetTarget(doubleAnimationUsingKeyFrame11, FromPage); Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame11, "(UIElement.Opacity)"); storyboard.Children.Add(doubleAnimationUsingKeyFrame11); try { storyboard.Begin(); if (completed != null) { completed.Invoke(); } } catch { base.Play(completed); } }
public static DoubleAnimationUsingKeyFrames CreateElasticYAnimation(TranslateTransform translate, double to, double seconds) { var elasticAni = new DoubleAnimationUsingKeyFrames { Duration = new Duration(TimeSpan.FromSeconds(seconds)), }; var easing = new EasingDoubleKeyFrame { Value = to, EasingFunction = new ElasticEase { EasingMode = EasingMode.EaseInOut, Oscillations = 3, Springiness = 8, } }; easing.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); elasticAni.KeyFrames.Add(easing); Storyboard.SetTargetProperty(elasticAni, "Y"); Storyboard.SetTarget(elasticAni, translate); return elasticAni; }
/// <summary> /// Provides the feathered animation for items /// when the Expander View goes from collapsed to expanded. /// </summary> internal void AnimateContainerDropDown() { for (int i = 0; i < Items.Count; i++) { FrameworkElement container = ContainerFromIndex(i) as FrameworkElement; if (container == null) { break; } Storyboard itemDropDown = new Storyboard(); EasingFunctionBase quadraticEase = new QuadraticEase { EasingMode = EasingMode.EaseOut }; int initialKeyTime = InitialKeyTime + (KeyTimeStep * i); int finalKeyTime = FinalKeyTime + (KeyTimeStep * i); TranslateTransform translation = new TranslateTransform(); container.RenderTransform = translation; DoubleAnimationUsingKeyFrames transAnimation = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame transKeyFrame1 = new EasingDoubleKeyFrame(); transKeyFrame1.EasingFunction = quadraticEase; transKeyFrame1.KeyTime = TimeSpan.FromMilliseconds(0.0); transKeyFrame1.Value = -150.0; EasingDoubleKeyFrame transKeyFrame2 = new EasingDoubleKeyFrame(); transKeyFrame2.EasingFunction = quadraticEase; transKeyFrame2.KeyTime = TimeSpan.FromMilliseconds(initialKeyTime); transKeyFrame2.Value = 0.0; EasingDoubleKeyFrame transKeyFrame3 = new EasingDoubleKeyFrame(); transKeyFrame3.EasingFunction = quadraticEase; transKeyFrame3.KeyTime = TimeSpan.FromMilliseconds(finalKeyTime); transKeyFrame3.Value = 0.0; transAnimation.KeyFrames.Add(transKeyFrame1); transAnimation.KeyFrames.Add(transKeyFrame2); transAnimation.KeyFrames.Add(transKeyFrame3); Storyboard.SetTarget(transAnimation, translation); Storyboard.SetTargetProperty(transAnimation, "Y"); itemDropDown.Children.Add(transAnimation); DoubleAnimationUsingKeyFrames opacityAnimation = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame opacityKeyFrame1 = new EasingDoubleKeyFrame(); opacityKeyFrame1.EasingFunction = quadraticEase; opacityKeyFrame1.KeyTime = TimeSpan.FromMilliseconds(0.0); opacityKeyFrame1.Value = 0.0; EasingDoubleKeyFrame opacityKeyFrame2 = new EasingDoubleKeyFrame(); opacityKeyFrame2.EasingFunction = quadraticEase; opacityKeyFrame2.KeyTime = TimeSpan.FromMilliseconds(initialKeyTime - 150); opacityKeyFrame2.Value = 0.0; EasingDoubleKeyFrame opacityKeyFrame3 = new EasingDoubleKeyFrame(); opacityKeyFrame3.EasingFunction = quadraticEase; opacityKeyFrame3.KeyTime = TimeSpan.FromMilliseconds(finalKeyTime); opacityKeyFrame3.Value = 1.0; opacityAnimation.KeyFrames.Add(opacityKeyFrame1); opacityAnimation.KeyFrames.Add(opacityKeyFrame2); opacityAnimation.KeyFrames.Add(opacityKeyFrame3); Storyboard.SetTarget(opacityAnimation, container); Storyboard.SetTargetProperty(opacityAnimation, "Opacity"); itemDropDown.Children.Add(opacityAnimation); itemDropDown.Begin(); } }
/// <summary> /// Scale X Animation Keyframes for tile animations. /// </summary> /// <returns></returns> private DoubleAnimationUsingKeyFrames CreateScaleXKeyFrames(int delay = 0) { var animation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)"); var frame = new EasingDoubleKeyFrame(); frame.KeyTime = new KeyTime(); frame.KeyTime = TimeSpan.FromMilliseconds(0); frame.Value = 0; var frameTwo = new EasingDoubleKeyFrame(); frameTwo.KeyTime = new KeyTime(); frameTwo.KeyTime = TimeSpan.FromMilliseconds(0 + delay); frameTwo.Value = 0; var frameThree = new EasingDoubleKeyFrame(); frameThree.KeyTime = new KeyTime(); frameThree.KeyTime = TimeSpan.FromMilliseconds(100 + delay); frameThree.Value = 1; //var frameThree = new EasingDoubleKeyFrame(); //frameThree.KeyTime = new KeyTime(); //frameThree.KeyTime = TimeSpan.FromMilliseconds(1000 + delay); //frameThree.Value = 1; animation.KeyFrames.Add(frame); animation.KeyFrames.Add(frameTwo); animation.KeyFrames.Add(frameThree); return animation; }
/// <summary> /// Reveals data points using a storyboard. /// </summary> /// <param name="dataPoints">The data points to change the state of. /// </param> /// <param name="dataPointCount">The number of data points in the sequence.</param> /// <param name="newState">The state to change to.</param> private void StaggeredStateChange(IEnumerable<DataPoint> dataPoints, int dataPointCount, DataPointState newState) { if (PlotArea == null || dataPointCount == 0) { return; } Storyboard stateChangeStoryBoard = new Storyboard(); dataPoints.ForEachWithIndex((dataPoint, count) => { dataPoint.Opacity = 0; // Create an Animation DoubleAnimationUsingKeyFrames objectAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(objectAnimationUsingKeyFrames, dataPoint); //TO-DO : Understand what is this Storyboard.SetTargetProperty(objectAnimationUsingKeyFrames, "Opacity"); EasingDoubleKeyFrame BeginKeyFrame = new EasingDoubleKeyFrame(); BeginKeyFrame.Value = 0; BeginKeyFrame.EasingFunction = new ElasticEase(); EasingDoubleKeyFrame EndKeyFrame = new EasingDoubleKeyFrame(); EndKeyFrame.Value = 100; EndKeyFrame.EasingFunction =new ElasticEase(); // Create the specified animation type switch (AnimationSequence) { case AnimationSequence.Simultaneous: BeginKeyFrame.KeyTime = TimeSpan.Zero; EndKeyFrame.KeyTime = TimeSpan.FromSeconds(1); break; case AnimationSequence.FirstToLast: BeginKeyFrame.KeyTime = TimeSpan.FromMilliseconds(1000 * ((double)count / dataPointCount)); EndKeyFrame.KeyTime = TimeSpan.FromMilliseconds(1000 * (((double)count+1)/ dataPointCount)); break; case AnimationSequence.LastToFirst: BeginKeyFrame.KeyTime = TimeSpan.FromMilliseconds(1000 * ((double)(dataPointCount - count - 1) / dataPointCount)); EndKeyFrame.KeyTime = TimeSpan.FromMilliseconds(1000 * ((double)(dataPointCount - count) / dataPointCount)); break; } objectAnimationUsingKeyFrames.KeyFrames.Add(BeginKeyFrame); objectAnimationUsingKeyFrames.KeyFrames.Add(EndKeyFrame); objectAnimationUsingKeyFrames.Duration = new TimeSpan(0, 0, 1); stateChangeStoryBoard.Children.Add(objectAnimationUsingKeyFrames); }); stateChangeStoryBoard.Duration = new TimeSpan(0, 1, 0); _storyBoardQueue.Enqueue( stateChangeStoryBoard, (sender, args) => { //stateChangeStoryBoard.Stop(); }); }
private Storyboard GetAngleStoryboard() { _currentStoryboard = new Storyboard(); DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); var from = new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(0), Value = _ellapsedCircle.EndAngle }; var to = new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(300), EasingFunction = new ExponentialEase(){ EasingMode = EasingMode.EaseOut}, Value = _ellapsedCircle.EndAngle + (360/this.GetDurationInSeconds()) }; da.FillBehavior = FillBehavior.HoldEnd; da.KeyFrames.Add(from); da.KeyFrames.Add(to); _currentStoryboard.Children.Add(da); da.EnableDependentAnimation = true; Storyboard.SetTarget(da, _ellapsedCircle); Storyboard.SetTargetProperty(da, "(RingSlice.EndAngle)"); return _currentStoryboard; }
public static Storyboard MakeTranslateStory(DependencyObject element, double fromValue, double toValue, TimeSpan lastTime, bool isX) { Storyboard sb = new Storyboard(); DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(frames, isX ? "(UIElement.RenderTransform).(CompositeTransform.TranslateX)" : "(UIElement.RenderTransform).(CompositeTransform.TranslateY)"); Storyboard.SetTarget(frames, element); EasingDoubleKeyFrame frame1 = new EasingDoubleKeyFrame(); frame1.KeyTime = new TimeSpan(0, 0, 0, 0); frame1.Value = fromValue; EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame(); frame2.KeyTime = lastTime; frame2.Value = toValue; frame2.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }; frames.KeyFrames.Add(frame1); frames.KeyFrames.Add(frame2); sb.FillBehavior = FillBehavior.HoldEnd; sb.Children.Add(frames); return sb; }
public static Storyboard MakeScaleAndDispearStory(DependencyObject element, TimeSpan lastTime) { Storyboard sb = new Storyboard(); DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(frames, "Opacity"); Storyboard.SetTarget(frames, element); EasingDoubleKeyFrame frame1 = new EasingDoubleKeyFrame(); frame1.KeyTime = new TimeSpan(0, 0, 0, 0); frame1.Value = 1; EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame(); frame2.KeyTime = lastTime; frame2.Value = 0; frames.KeyFrames.Add(frame1); frames.KeyFrames.Add(frame2); DoubleAnimationUsingKeyFrames frames1 = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(frames1, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)"); Storyboard.SetTarget(frames1, element); EasingDoubleKeyFrame frame11 = new EasingDoubleKeyFrame(); frame11.KeyTime = new TimeSpan(0, 0, 0, 0); frame11.Value = 1; EasingDoubleKeyFrame frame12 = new EasingDoubleKeyFrame(); frame12.KeyTime = lastTime; frame12.Value = 5; frames1.KeyFrames.Add(frame11); frames1.KeyFrames.Add(frame12); DoubleAnimationUsingKeyFrames frames2 = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(frames2, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)"); Storyboard.SetTarget(frames2, element); EasingDoubleKeyFrame frame21 = new EasingDoubleKeyFrame(); frame21.KeyTime = new TimeSpan(0, 0, 0, 0); frame21.Value = 1; EasingDoubleKeyFrame frame22 = new EasingDoubleKeyFrame(); frame22.KeyTime = lastTime; frame22.Value = 5; frames2.KeyFrames.Add(frame21); frames2.KeyFrames.Add(frame22); sb.FillBehavior = FillBehavior.HoldEnd; sb.Children.Add(frames1); sb.Children.Add(frames2); sb.Children.Add(frames); return sb; }
private static DoubleAnimationUsingKeyFrames CreateScaleYKeyFrames(int delay = 0) { var animation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)"); var frameA = new EasingDoubleKeyFrame(); frameA.KeyTime = new KeyTime(); frameA.KeyTime = TimeSpan.FromMilliseconds(0); frameA.Value = 0; var frameB = new EasingDoubleKeyFrame(); frameB.KeyTime = new KeyTime(); frameB.KeyTime = TimeSpan.FromMilliseconds(0 + delay); frameB.Value = 0; var frameC = new EasingDoubleKeyFrame(); frameC.KeyTime = new KeyTime(); frameC.KeyTime = TimeSpan.FromMilliseconds(100 + delay); frameC.Value = 1; animation.KeyFrames.Add(frameA); animation.KeyFrames.Add(frameB); animation.KeyFrames.Add(frameC); return animation; }
/// <summary> /// Gets the template parts and sets event handlers. /// </summary> protected override void OnApplyTemplate() { if (_expanderPanel != null) { _expanderPanel.Tapped -= OnExpanderPanelTap; } base.OnApplyTemplate(); _expanderPanel = base.GetTemplateChild(ExpanderPanel) as Grid; _expandedToCollapsedFrame = base.GetTemplateChild(ExpandedToCollapsedKeyFrame) as EasingDoubleKeyFrame; _collapsedToExpandedFrame = base.GetTemplateChild(CollapsedToExpandedKeyFrame) as EasingDoubleKeyFrame; _itemsCanvas = base.GetTemplateChild("ItemsCanvas") as Canvas; VisualState expandedState = (base.GetTemplateChild(ExpandedState) as VisualState); if (expandedState != null) { _expandedStateAnimation = expandedState.Storyboard.Children[0] as DoubleAnimation; } _presenter = base.GetTemplateChild(Presenter) as ItemsPresenter; if (_presenter != null) { _presenter.SizeChanged += OnPresenterSizeChanged; } if (_expanderPanel != null) { _expanderPanel.Tapped += OnExpanderPanelTap; } UpdateVisualState(false); }
private DoubleAnimationUsingKeyFrames CreateOpacityKeyFrames(int delay = 0) { var opacityAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(opacityAnimation, "(UIElement.Opacity)"); var oFrameZero = new EasingDoubleKeyFrame(); oFrameZero.KeyTime = new KeyTime(); oFrameZero.KeyTime = TimeSpan.FromMilliseconds(0); oFrameZero.Value = 1; var oFrameOne = new EasingDoubleKeyFrame(); oFrameOne.KeyTime = new KeyTime(); oFrameOne.KeyTime = TimeSpan.FromMilliseconds(500 + delay); oFrameOne.Value = 1; var oFrameTwo = new EasingDoubleKeyFrame(); oFrameTwo.KeyTime = new KeyTime(); oFrameTwo.KeyTime = TimeSpan.FromMilliseconds(2000 + delay); oFrameTwo.Value = 0; oFrameTwo.EasingFunction = new QuinticEase(); oFrameTwo.EasingFunction.EasingMode = EasingMode.EaseOut; opacityAnimation.KeyFrames.Add(oFrameZero); opacityAnimation.KeyFrames.Add(oFrameOne); opacityAnimation.KeyFrames.Add(oFrameTwo); return opacityAnimation; }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); ContentPresenter = (ContentControl)GetTemplateChild("ContentPresenter"); planeProjection = (PlaneProjection)GetTemplateChild("Rotator"); LayoutRoot = (FrameworkElement)GetTemplateChild("LayoutRoot"); Animation = (Storyboard)GetTemplateChild("Animation"); Animation.Completed += Animation_Completed; rotationKeyFrame = (EasingDoubleKeyFrame)GetTemplateChild("rotationKeyFrame"); offestZKeyFrame = (EasingDoubleKeyFrame)GetTemplateChild("offestZKeyFrame"); scaleXKeyFrame = (EasingDoubleKeyFrame)GetTemplateChild("scaleXKeyFrame"); scaleYKeyFrame = (EasingDoubleKeyFrame)GetTemplateChild("scaleYKeyFrame"); scaleTransform = (ScaleTransform)GetTemplateChild("scaleTransform"); planeProjection.RotationY = yRotation; planeProjection.LocalOffsetZ = zOffset; if (ContentPresenter != null) { ContentPresenter.Tapped += ContentPresenter_Tapped; } if (Animation != null) { xAnimation = new DoubleAnimation(); Animation.Children.Add(xAnimation); Storyboard.SetTarget(xAnimation, this); Storyboard.SetTargetProperty(xAnimation, "(Canvas.Left)"); } }
private DoubleAnimationUsingKeyFrames CreateTranslationKeyFrames(int playerViewModelIndex, TileAnimationDirection direction, Grid tile, int delay = 0) { Point BeginPoint; Point EndPoint; var animation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)"); var dumpCircleGt = InnerDumpCircle.TransformToVisual(pageRoot); var animationTargetContainer = PlayerPanel.ItemContainerGenerator.ContainerFromIndex(playerViewModelIndex); var grid = VisualTreeHelper.GetChild(animationTargetContainer, 0) as Grid; var playerViewModelGt = grid.TransformToVisual(pageRoot); if (direction == TileAnimationDirection.Down) { BeginPoint = dumpCircleGt.TransformPoint(new Point(0, 0)); EndPoint = playerViewModelGt.TransformPoint(new Point(0, 0)); tile.Margin = new Thickness(BeginPoint.X + InnerDumpCircle.Width / 2 - tile.Width / 2, BeginPoint.Y - tile.Height / 2 + 10/* + InnerDumpCircle.Height / 2*/, 0, 0); } else { EndPoint = dumpCircleGt.TransformPoint(new Point(0, 0)); BeginPoint = playerViewModelGt.TransformPoint(new Point(0, 0)); tile.Margin = new Thickness(BeginPoint.X + InnerDumpCircle.Width / 2 + 15, tile.Height / 2 + 10, 0, 0); } var acFrame = new EasingDoubleKeyFrame(); acFrame.KeyTime = new KeyTime(); acFrame.KeyTime = TimeSpan.FromMilliseconds(0); acFrame.Value = BeginPoint.Y; var bcFrame = new EasingDoubleKeyFrame(); bcFrame.KeyTime = new KeyTime(); bcFrame.KeyTime = TimeSpan.FromMilliseconds(0 + delay); bcFrame.Value = BeginPoint.Y; var cFrame = new EasingDoubleKeyFrame(); cFrame.KeyTime = new KeyTime(); cFrame.KeyTime = TimeSpan.FromMilliseconds(100 + delay); cFrame.Value = BeginPoint.Y; var dFrame = new EasingDoubleKeyFrame(); dFrame.KeyTime = new KeyTime(); dFrame.KeyTime = TimeSpan.FromMilliseconds(500 + delay); dFrame.Value = EndPoint.Y; dFrame.EasingFunction = new QuadraticEase(); dFrame.EasingFunction.EasingMode = EasingMode.EaseInOut; animation.KeyFrames.Add(acFrame); animation.KeyFrames.Add(bcFrame); animation.KeyFrames.Add(cFrame); animation.KeyFrames.Add(dFrame); return animation; }