private Timeline CreateExpandIn(ITransitionEffectSubject effectSubject) { var scaleXAnimation = new DoubleAnimationUsingKeyFrames(); var zeroFrame = new DiscreteDoubleKeyFrame(0.0); var startFrame = new DiscreteDoubleKeyFrame(.5, effectSubject.Offset + OffsetTime); var endFrame = new EasingDoubleKeyFrame(1, effectSubject.Offset + OffsetTime + Duration) { EasingFunction = new SineEase() }; scaleXAnimation.KeyFrames.Add(zeroFrame); scaleXAnimation.KeyFrames.Add(startFrame); scaleXAnimation.KeyFrames.Add(endFrame); Storyboard.SetTargetName(scaleXAnimation, effectSubject.ScaleTransformName); Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath(ScaleTransform.ScaleXProperty)); var scaleYAnimation = scaleXAnimation.Clone(); Storyboard.SetTargetName(scaleYAnimation, effectSubject.ScaleTransformName); Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath(ScaleTransform.ScaleYProperty)); var parallelTimeline = new ParallelTimeline(); parallelTimeline.Children.Add(scaleXAnimation); parallelTimeline.Children.Add(scaleYAnimation); return(parallelTimeline); }
public ReusableFollowTracker() { _timeline = new ParallelTimeline(null, Duration.Forever); _timeClock = _timeline.CreateClock(); _timeClock.Controller?.Begin(); _lastTime = TimeSpan.FromSeconds(0); }
// internally, hook up each tick requested private void setUpTicks() { this.timeClocks = new Clock[timeArray.Length]; ParallelTimeline eventTimeline; foreach(int duration in timeArray) { eventTimeline = new ParallelTimeline(); eventTimeline.BeginTime = null; eventTimeline.Duration = new Duration(TimeSpan.FromMilliseconds(duration)); timeClocks[timeClockIndex] = eventTimeline.CreateClock(); timeClocks[timeClockIndex].CurrentStateInvalidated += new EventHandler(OnEnded); // The last time in the list should be the only one with CurrentTimeInvalidated hooked up if (timeClockIndex == (timeArray.Length - 1)) { timeClocks[timeClockIndex].CurrentTimeInvalidated += new EventHandler(EnsureIndividualTick); } timeClocks[timeClockIndex].Controller.Begin(); timeClockIndex ++; } timeClockIndex ++; }
///<summary>子时间线状态改变</summary> void ptl_CurrentStateInvalidated(object sender, EventArgs e) { Clock clock = sender as Clock; ParallelTimeline tl = clock.Timeline as ParallelTimeline; int idx = (int)tl.GetValue(ToolTipService.ToolTipProperty); EventInfo ei = eventInfoes.FirstOrDefault(p => p.idx == idx); if (clock.CurrentState == ClockState.Active && sb.GetCurrentState(this) == ClockState.Active) { //if (!sb.GetIsPaused(this)) { //ucmap.BaseMap.zMapControl.CenterPoint = MapHelper.getOffsetPoint(ei.center, new Point(175, 0), ucmap.BaseMap.zMapControl.Layers[0]); root.earth.camera.aniLook(ei.obj.VecLocation, 0); root.earth.UpdateModel(); //infopanel.Visible = true; //infopanel.Location = ei.center; //infopanel.Content = ei; } ei.visibility = Visibility.Visible; ei.background = new SolidColorBrush(Colors.Chocolate); } else if (clock.CurrentState == ClockState.Filling) { ei.visibility = Visibility.Visible; ei.background = Brushes.Transparent; } else { ei.visibility = Visibility.Collapsed; ei.background = Brushes.Transparent; } }
public void AnimateShift(double deltaX, double deltaY, Action <SquareItem> action) { DoubleAnimation shiftX = new DoubleAnimation(); shiftX.From = 0; shiftX.To = deltaX; shiftX.Duration = new Duration(TimeSpan.FromSeconds(0.6)); DoubleAnimation shiftY = new DoubleAnimation(); shiftY.From = 0; shiftY.To = deltaY; shiftY.Duration = shiftX.Duration; ParallelTimeline timeline = new ParallelTimeline(); timeline.Children.Add(shiftX); timeline.Children.Add(shiftY); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(timeline); Storyboard.SetTarget(shiftX, this); Storyboard.SetTarget(shiftY, this); Storyboard.SetTargetProperty(shiftX, new PropertyPath("DeltaXTransform")); Storyboard.SetTargetProperty(shiftY, new PropertyPath("DeltaYTransform")); storyboard.Completed += new EventHandler((sender, e) => action(this)); storyboard.Begin(); }
private Menu() { InitializeComponent(); goUpDownAnimation = ((Storyboard)MainWindow.Instance.Resources["ResizeAnimation"]).Clone(); ChangeKeyTimeOfAllKeyFrames(goUpDownAnimation, (KeyTime)Application.Current.Resources["AnimationKeyTime"]); IEasingFunction goUpDownAnimationEasingFunction = (IEasingFunction)Application.Current.Resources["AnimationEasingFunction"]; foreach (IKeyFrameAnimation animation in goUpDownAnimation.Children) { ((EasingDoubleKeyFrame)animation.KeyFrames[0]).EasingFunction = goUpDownAnimationEasingFunction; } goUpDownWindowResizeAnimationAddition = (ParallelTimeline)Resources["GoUpDownWindowResizeAnimationAddition"]; goUpDownAnimation.Children.Add(goUpDownWindowResizeAnimationAddition); flyAnimation = ((Storyboard)MainWindow.Instance.Resources["ResizeAnimation"]).Clone(); ChangeKeyTimeOfAllKeyFrames(flyAnimation, (KeyTime)Resources["FlyKeyTime"]); flyAnimation.Children.Add((ParallelTimeline)Resources["FlyWindowResizeAnimationAddition"]); void ChangeKeyTimeOfAllKeyFrames(TimelineGroup timelineGroup, KeyTime keyTime) { foreach (IKeyFrameAnimation animation in timelineGroup.Children) { ((IKeyFrame)animation.KeyFrames[0]).KeyTime = keyTime; } } }
public object Load(IContentManager contentManager) { Animation animation = new Animation(); animation.Mode = Mode; animation.Direction = Direction; animation.Fps = Fps; animation.FrameCount = FrameCount; if (Timelines.Count > 1) { ParallelTimeline parallelTimeline = new ParallelTimeline(); parallelTimeline.BeginTime = 0; parallelTimeline.EndTime = 1; parallelTimeline.Duration = 1; for (int i = 0; i < Timelines.Count; i++) { ITimeline timeline = (ITimeline)Timelines[i].Load(contentManager); parallelTimeline.Children.Add(timeline); } animation.Timeline = parallelTimeline; } else if (Timelines.Count > 0) { animation.Timeline = (ITimeline)Timelines[0].Load(contentManager); } return(animation); }
public Timeline GetTimeline() { ResetTimelines(); ParallelTimeline timeline = new ParallelTimeline(); foreach (Animation animation in animationsList.Animations) { switch (animation) { case VisibilityAnimation visibilityAnimation: AddVisibilityAnimation(visibilityAnimation); break; case PositionAnimation positionAnimation: AddPositionAnimation(positionAnimation); break; case OpacityAnimation opacityTransformation: AddOpacityAnimation(opacityTransformation); break; case ScaleAnimation scaleAnimation: AddScaleAnimation(scaleAnimation); break; case AngleAnimation angleAnimation: AddAngleAnimation(angleAnimation); break; case SpriteAnimation spriteAnimation: AddSpriteAnimation(spriteAnimation); break; } } timeline.Children.Add(VisibilityTimeline); timeline.Children.Add(PositionXTimeline); timeline.Children.Add(PositionYTimeline); timeline.Children.Add(OpacityTimeline); timeline.Children.Add(ScaleXTimeline); timeline.Children.Add(ScaleYTimeline); timeline.Children.Add(AngleTimeline); if (Control is UISpriteCollectionModel) { for (int i = 0; i < SpriteTimelinesCollection.Length; i++) { SpriteTimeline.Children.Add(SpriteTimelinesCollection[i]); } } timeline.Children.Add(SpriteTimeline); return(timeline); }
private MenuToGameTransition() { InitializeComponent(); flyWindowResizeAnimation = ((Storyboard)MainWindow.Instance.Resources["ResizeAnimation"]).Clone(); ParallelTimeline flyWindowResizeAnimationAddition = (ParallelTimeline)Resources["FlyWindowResizeAnimationAddition"]; Helpers.SetAnimationKeyFrameValue(flyWindowResizeAnimationAddition, 0, 0, (GamePage.requestedSize.Width - RequestedSize.Width) / 2d); Helpers.SetAnimationKeyFrameValue(flyWindowResizeAnimationAddition, 1, 0, (GamePage.requestedSize.Height - RequestedSize.Height) / 2d); flyWindowResizeAnimation.Children.Add(flyWindowResizeAnimationAddition); }
/// <summary> /// Starts the particle running or restarts the particle if it has expired /// </summary> /// <param name="rerun"></param> private void Run(bool rerun) { // only init the particle if it hasn't been run yet if (!rerun) { NameScope.SetNameScope(this, new NameScope()); this.Name = String.Format("p{0}", Particle.ParticleNo++); this.RegisterName(this.Name, this); this.Width = ParticleSystem.random.NextDouble(Owner.MinParticleWidth, Owner.MaxParticleWidth); this.Height = ParticleSystem.random.NextDouble(Owner.MinParticleHeight, Owner.MaxParticleHeight); this.particleSolidColorBrush = new SolidColorBrush(Colors.White); this.RegisterName(String.Format("{0}Brush", this.Name), particleSolidColorBrush); this.Background = particleSolidColorBrush; } // create the storyboard for this particle and hold its end behavior mStoryboard = new Storyboard(); mStoryboard.FillBehavior = FillBehavior.HoldEnd; // create a parallel timeline for the the opacity and background changes. ParallelTimeline pt = new ParallelTimeline(TimeSpan.FromSeconds(0)); // the timeline for the opacity change using the particle Start and End Opacity DoubleAnimation daOpacity = new DoubleAnimation(StartOpacity, EndOpacity, new Duration(TimeSpan.FromSeconds(this.LifeSpan))); Storyboard.SetTargetName(daOpacity, this.Name); Storyboard.SetTargetProperty(daOpacity, new PropertyPath(Particle.OpacityProperty)); // the timeline for the background color change using a colorkeyframecollection ColorAnimationUsingKeyFrames daBackground = new ColorAnimationUsingKeyFrames(); daBackground.Duration = new Duration(TimeSpan.FromSeconds(this.LifeSpan)); daBackground.KeyFrames = BackgroundColors; Storyboard.SetTargetName(daBackground, String.Format("{0}Brush", this.Name)); Storyboard.SetTargetProperty(daBackground, new PropertyPath(SolidColorBrush.ColorProperty)); pt.Children.Add(daOpacity); pt.Children.Add(daBackground); mStoryboard.Children.Add(pt); // the first time this is run begin the storyboard on load. if (!rerun) { this.Loaded += delegate(object sender, RoutedEventArgs args) { mStoryboard.Begin(this, true); }; } mIsAlive = true; }
public void AnimateTranslateXTo(double to) { Storyboard s = (Storyboard)this.FindResource("TranslateXStoryboard"); // elementbinding doesn't work in Beta bits. So create the animation in code for now ParallelTimeline pt = s.Children[0] as ParallelTimeline; pt.Children.Clear(); double duration = (double)this.GetValue(Rotate3D.DurationTimeProperty); pt.Children.Add(new DoubleAnimation(to, new Duration(TimeSpan.FromSeconds(duration)), FillBehavior.HoldEnd)); this.BeginStoryboard(s); }
private Menu() { InitializeComponent(); goUpDownAnimation = ((Storyboard)MainWindow.Instance.Resources["ResizeAnimation"]).Clone(); goUpDownWindowResizeAnimationAddition = (ParallelTimeline)Resources["GoUpDownWindowResizeAnimationAddition"]; goUpDownAnimation.Children.Add(goUpDownWindowResizeAnimationAddition); flyAnimation = ((Storyboard)MainWindow.Instance.Resources["ResizeAnimation"]).Clone(); KeyTime flyKeyTime = (KeyTime)Resources["FlyKeyTime"]; foreach (IKeyFrameAnimation animation in flyAnimation.Children) { ((IKeyFrame)animation.KeyFrames[0]).KeyTime = flyKeyTime; } flyAnimation.Children.Add((ParallelTimeline)Resources["FlyWindowResizeAnimationAddition"]); }
private void ResetTimelines() { VisibilityTimeline = new DoubleAnimationUsingKeyFrames(); PositionXTimeline = new DoubleAnimationUsingKeyFrames(); PositionYTimeline = new DoubleAnimationUsingKeyFrames(); OpacityTimeline = new DoubleAnimationUsingKeyFrames(); ScaleXTimeline = new DoubleAnimationUsingKeyFrames(); ScaleYTimeline = new DoubleAnimationUsingKeyFrames(); AngleTimeline = new DoubleAnimationUsingKeyFrames(); if (Control?.UIElement is SpriteCollection spriteCollection) { SpriteTimelinesCollection = new DoubleAnimationUsingKeyFrames[spriteCollection.ChildSpriteGroups.Count]; for (int i = 0; i < spriteCollection.ChildSpriteGroups.Count; i++) { SpriteTimelinesCollection[i] = new DoubleAnimationUsingKeyFrames(); } } SpriteTimeline = new ParallelTimeline(); }
private void Animate(int col) { double move = col * -MODEL_OFFSET; Storyboard storyboard = new Storyboard(); ParallelTimeline timeline = new ParallelTimeline(); timeline.BeginTime = TimeSpan.FromSeconds(0); timeline.Duration = TimeSpan.FromSeconds(2); //do move DoubleAnimation daMove = new DoubleAnimation(move, new Duration(TimeSpan.FromSeconds(2))); daMove.DecelerationRatio = 1.0; Storyboard.SetTargetName(daMove, "contTrans"); Storyboard.SetTargetProperty(daMove, new PropertyPath(TranslateTransform3D.OffsetXProperty)); //do angle double angle = col > Wall3dHelper.COLUMNS / 2 ? -15 : 15; DoubleAnimation daAngle = new DoubleAnimation(angle, new Duration(TimeSpan.FromSeconds(0.8))); Storyboard.SetTargetName(daAngle, "contAngle"); Storyboard.SetTargetProperty(daAngle, new PropertyPath(AxisAngleRotation3D.AngleProperty)); DoubleAnimation daAngle2 = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(1))); daAngle2.BeginTime = daAngle.Duration.TimeSpan; Storyboard.SetTargetName(daAngle2, "contAngle"); Storyboard.SetTargetProperty(daAngle2, new PropertyPath(AxisAngleRotation3D.AngleProperty)); timeline.Children.Add(daMove); timeline.Children.Add(daAngle); timeline.Children.Add(daAngle2); storyboard.Children.Add(timeline); storyboard.Begin(this); }
public void ParallelClockBasicTest() { ParallelTimeline timeline = new ParallelTimeline(); timeline.Children.Add(new TestTimeline()); timeline.Children.Add(new TestTimeline { BeginTime = TimeSpan.FromSeconds(2) }); TimelineClock clock = (TimelineClock)timeline.CreateClock(); clock.Tick(TimeSpan.FromSeconds(-0.2)); Assert.AreEqual(Granular.Compatibility.TimeSpan.MinValue, clock.CurrentState.PreviousTick); Assert.AreEqual(TimeSpan.Zero, clock.CurrentState.NextTick); Assert.AreEqual(ClockProgressState.BeforeStarted, clock.CurrentState.ProgressState); clock.Tick(TimeSpan.FromSeconds(0.2)); Assert.AreEqual(TimeSpan.FromSeconds(0.2), clock.CurrentState.PreviousTick); Assert.AreEqual(TimeSpan.FromSeconds(0.2), clock.CurrentState.NextTick); Assert.AreEqual(ClockProgressState.Active, clock.CurrentState.ProgressState); clock.Tick(TimeSpan.FromSeconds(1.2)); Assert.AreEqual(TimeSpan.FromSeconds(1), clock.CurrentState.PreviousTick); Assert.AreEqual(TimeSpan.FromSeconds(2), clock.CurrentState.NextTick); Assert.AreEqual(ClockProgressState.Active, clock.CurrentState.ProgressState); clock.Tick(TimeSpan.FromSeconds(2.2)); Assert.AreEqual(TimeSpan.FromSeconds(2.2), clock.CurrentState.PreviousTick); Assert.AreEqual(TimeSpan.FromSeconds(2.2), clock.CurrentState.NextTick); Assert.AreEqual(ClockProgressState.Active, clock.CurrentState.ProgressState); clock.Tick(TimeSpan.FromSeconds(3.2)); Assert.AreEqual(TimeSpan.FromSeconds(3), clock.CurrentState.PreviousTick); Assert.AreEqual(Granular.Compatibility.TimeSpan.MaxValue, clock.CurrentState.NextTick); Assert.AreEqual(ClockProgressState.AfterEnded, clock.CurrentState.ProgressState); }
public BeginTimeExample() { // Create a name scope for the page. NameScope.SetNameScope(this, new NameScope()); this.WindowTitle = "BeginTime Example"; StackPanel myStackPanel = new StackPanel(); myStackPanel.Margin = new Thickness(20); Border myBorder = new Border(); Color myColor = new Color(); SolidColorBrush mySolidColorBrush = new SolidColorBrush(Color.FromArgb(153, 255, 255, 255)); mySolidColorBrush.Color = myColor; myBorder.Background = mySolidColorBrush; TextBlock myTextBlock = new TextBlock(); myTextBlock.Margin = new Thickness(20); myTextBlock.Text = "This example shows how the BeginTime property determines when a timeline starts."; myTextBlock.Text += " Several rectangles are animated by DoubleAnimations with identical durations and"; myTextBlock.Text += " target values, but with different BeginTime settings."; myBorder.Child = myTextBlock; myStackPanel.Children.Add(myBorder); myTextBlock = new TextBlock(); myTextBlock.Text = "Animation BeginTime: \"0:0:0\" "; myStackPanel.Children.Add(myTextBlock); Rectangle defaultBeginTimeRectangle = new Rectangle(); defaultBeginTimeRectangle.Name = "defaultBeginTimeRectangle"; this.RegisterName(defaultBeginTimeRectangle.Name, defaultBeginTimeRectangle); defaultBeginTimeRectangle.Width = 20; defaultBeginTimeRectangle.Height = 20; myColor = new Color(); mySolidColorBrush = new SolidColorBrush(Color.FromArgb(170, 51, 51, 255)); defaultBeginTimeRectangle.Fill = mySolidColorBrush; defaultBeginTimeRectangle.HorizontalAlignment = HorizontalAlignment.Left; myStackPanel.Children.Add(defaultBeginTimeRectangle); myTextBlock = new TextBlock(); myTextBlock.Margin = new Thickness(0, 20, 0, 0); myTextBlock.Text = "Animation BeginTime: \"0:0:5\" \n"; myStackPanel.Children.Add(myTextBlock); Rectangle delayedBeginTimeRectangle = new Rectangle(); delayedBeginTimeRectangle.Name = "delayedBeginTimeRectangle"; this.RegisterName(delayedBeginTimeRectangle.Name, delayedBeginTimeRectangle); delayedBeginTimeRectangle.Width = 20; delayedBeginTimeRectangle.Height = 20; myColor = new Color(); mySolidColorBrush = new SolidColorBrush(Color.FromArgb(170, 51, 51, 255)); delayedBeginTimeRectangle.Fill = mySolidColorBrush; delayedBeginTimeRectangle.HorizontalAlignment = HorizontalAlignment.Left; myStackPanel.Children.Add(delayedBeginTimeRectangle); myTextBlock = new TextBlock(); myTextBlock.Text = "\nParent Timeline BeginTime: \"0:0:5\" \nAnimation BeginTime: \"0:0:5\" "; myStackPanel.Children.Add(myTextBlock); Rectangle delayedAnimationWithDelayedParentRectangle = new Rectangle(); delayedAnimationWithDelayedParentRectangle.Name = "delayedAnimationWithDelayedParentRectangle"; this.RegisterName(delayedAnimationWithDelayedParentRectangle.Name, delayedAnimationWithDelayedParentRectangle); delayedAnimationWithDelayedParentRectangle.Width = 20; delayedAnimationWithDelayedParentRectangle.Height = 20; myColor = new Color(); mySolidColorBrush = new SolidColorBrush(Color.FromArgb(170, 51, 51, 255)); delayedAnimationWithDelayedParentRectangle.Fill = mySolidColorBrush; delayedAnimationWithDelayedParentRectangle.HorizontalAlignment = HorizontalAlignment.Left; myStackPanel.Children.Add(delayedAnimationWithDelayedParentRectangle); // // Create an animation with no delay in the start time. // DoubleAnimation myDoubleAnimation = new DoubleAnimation(); Storyboard.SetTargetName(myDoubleAnimation, defaultBeginTimeRectangle.Name); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)); myDoubleAnimation.From = 20; myDoubleAnimation.To = 400; myDoubleAnimation.BeginTime = TimeSpan.FromSeconds(0); myDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); myDoubleAnimation.FillBehavior = FillBehavior.HoldEnd; // // Create an animation with a 5 second delay in the start time. // DoubleAnimation myDelayedDoubleAnimation = new DoubleAnimation(); Storyboard.SetTargetName(myDelayedDoubleAnimation, delayedBeginTimeRectangle.Name); Storyboard.SetTargetProperty(myDelayedDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)); myDelayedDoubleAnimation.BeginTime = TimeSpan.FromSeconds(5); myDelayedDoubleAnimation.From = 20; myDelayedDoubleAnimation.To = 400; myDelayedDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); myDelayedDoubleAnimation.FillBehavior = FillBehavior.HoldEnd; // // Create an animation with a 5 second delay in both the parent and // child timelines. // ParallelTimeline myParallelTimeline = new ParallelTimeline(); myParallelTimeline.BeginTime = TimeSpan.FromSeconds(5); DoubleAnimation myParallelDelayedDoubleAnimation = new DoubleAnimation(); Storyboard.SetTargetName(myParallelDelayedDoubleAnimation, delayedAnimationWithDelayedParentRectangle.Name); Storyboard.SetTargetProperty(myParallelDelayedDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)); myParallelDelayedDoubleAnimation.From = 20; myParallelDelayedDoubleAnimation.To = 400; myParallelDelayedDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); myParallelDelayedDoubleAnimation.FillBehavior = FillBehavior.HoldEnd; myParallelDelayedDoubleAnimation.BeginTime = TimeSpan.FromSeconds(5); // // Create a Storyboard to contain the animations and add the animations to the Storyboard // Storyboard myStoryboard = new Storyboard(); myStoryboard.Children.Add(myDoubleAnimation); myStoryboard.Children.Add(myDelayedDoubleAnimation); myParallelTimeline.Children.Add(myParallelDelayedDoubleAnimation); myStoryboard.Children.Add(myParallelTimeline); // // Create the button to restart the animations // Button myButton = new Button(); myButton.Margin = new Thickness(0, 30, 0, 0); myButton.HorizontalAlignment = HorizontalAlignment.Left; myButton.Content = "Restart Animations"; myStackPanel.Children.Add(myButton); // // Create an EventTrigger and a BeginStoryboard action to start // the storyboard // BeginStoryboard myBeginStoryboard = new BeginStoryboard(); myBeginStoryboard.Storyboard = myStoryboard; EventTrigger myEventTrigger = new EventTrigger(); myEventTrigger.RoutedEvent = Button.ClickEvent; myEventTrigger.SourceName = myButton.Name; myEventTrigger.Actions.Add(myBeginStoryboard); myStackPanel.Triggers.Add(myEventTrigger); this.Content = myStackPanel; }
private void AnimateProgress(HitObjectElement element) { if (ViewModel.VisibleHitObject == null) { return; } // Set the pixel length to the pixel length of the graph var maxCompletion = GetMaxCompletion(); element.CustomPixelLength = maxCompletion * ViewModel.PixelLength; var graphDuration = ViewModel.GraphDuration; var extraDuration = graphDuration.Add(TimeSpan.FromSeconds(1)); DoubleAnimationBase animation; if (ViewModel.GraphModeSetting == SlideratorVm.GraphMode.Velocity) { animation = new GraphIntegralDoubleAnimation { GraphState = Graph.GetGraphState(), From = Graph.MinX, To = Graph.MaxX, Duration = graphDuration, BeginTime = TimeSpan.Zero, // Here we use SvGraphMultiplier to get an accurate conversion from SV to slider completion per beat // Completion = (100 * SliderMultiplier / PixelLength) * SV * Beats Multiplier = ViewModel.SvGraphMultiplier / maxCompletion } } ; else { animation = new GraphDoubleAnimation { GraphState = Graph.GetGraphState(), From = Graph.MinX, To = Graph.MaxX, Duration = graphDuration, BeginTime = TimeSpan.Zero, Multiplier = 1 / maxCompletion } }; var animation2 = new DoubleAnimation(-1, -1, TimeSpan.FromSeconds(1)) { BeginTime = graphDuration }; Storyboard.SetTarget(animation, element); Storyboard.SetTarget(animation2, element); Storyboard.SetTargetProperty(animation, new PropertyPath(HitObjectElement.ProgressProperty)); Storyboard.SetTargetProperty(animation2, new PropertyPath(HitObjectElement.ProgressProperty)); var timeline = new ParallelTimeline { RepeatBehavior = RepeatBehavior.Forever, Duration = extraDuration }; timeline.Children.Add(animation); timeline.Children.Add(animation2); var storyboard = new Storyboard(); storyboard.Children.Add(timeline); element.BeginStoryboard(storyboard); }
public AutoReverseExample() { // Create a name scope for the page. NameScope.SetNameScope(this, new NameScope()); StackPanel myStackPanel = new StackPanel(); myStackPanel.Margin = new Thickness(20); Border myBorder = new Border(); TextBlock myTextBlock = new TextBlock(); myTextBlock.Margin = new Thickness(20); myTextBlock.Text = "This example shows how to use the AutoReverse property to make a"; myTextBlock.Text += " timeline play backwards at the end of each iteration. Several rectangles are"; myTextBlock.Text += " animated by DoubleAnimations with identical durations and target values, but with different "; myTextBlock.Text += " AutoReverse and RepeatBehavior settings."; myBorder.Child = myTextBlock; myStackPanel.Children.Add(myBorder); myTextBlock = new TextBlock(); myTextBlock.Text = "AutoReverse=\"False\" (Default)."; myStackPanel.Children.Add(myTextBlock); // // Create the rectangles to animate // Rectangle withoutAutoReverseRectangle = new Rectangle(); withoutAutoReverseRectangle.Name = "withoutAutoReverseRectangle"; this.RegisterName(withoutAutoReverseRectangle.Name, withoutAutoReverseRectangle); withoutAutoReverseRectangle.Width = 100; withoutAutoReverseRectangle.Height = 20; SolidColorBrush mySolidColorBrush = new SolidColorBrush(Color.FromArgb(170, 51, 51, 255)); withoutAutoReverseRectangle.Fill = mySolidColorBrush; withoutAutoReverseRectangle.HorizontalAlignment = HorizontalAlignment.Left; myStackPanel.Children.Add(withoutAutoReverseRectangle); myTextBlock = new TextBlock(); myTextBlock.Margin = new Thickness(0, 20, 0, 0); myTextBlock.Text = "AutoReverse=\"True\"."; myStackPanel.Children.Add(myTextBlock); Rectangle autoReverseRectangle = new Rectangle(); autoReverseRectangle.Name = "autoReverseRectangle"; this.RegisterName(autoReverseRectangle.Name, autoReverseRectangle); autoReverseRectangle.Width = 100; autoReverseRectangle.Height = 20; autoReverseRectangle.Fill = mySolidColorBrush; autoReverseRectangle.HorizontalAlignment = HorizontalAlignment.Left; myStackPanel.Children.Add(autoReverseRectangle); myTextBlock = new TextBlock(); myTextBlock.Margin = new Thickness(0, 20, 0, 0); myTextBlock.Text = "In this example, AutoReverse=\"True\" \nRepeatBehavior=\"2x\"."; myStackPanel.Children.Add(myTextBlock); Rectangle autoReverseRectangleWithRepeats = new Rectangle(); autoReverseRectangleWithRepeats.Name = "autoReverseRectangleWithRepeats"; this.RegisterName(autoReverseRectangleWithRepeats.Name, autoReverseRectangleWithRepeats); autoReverseRectangleWithRepeats.Width = 100; autoReverseRectangleWithRepeats.Height = 20; autoReverseRectangleWithRepeats.Fill = mySolidColorBrush; autoReverseRectangleWithRepeats.HorizontalAlignment = HorizontalAlignment.Left; myStackPanel.Children.Add(autoReverseRectangleWithRepeats); myTextBlock = new TextBlock(); myTextBlock.Margin = new Thickness(0, 20, 0, 0); myTextBlock.Text = "In this example, AutoReverse=\"True\" and RepeatBehavior=\"2x\" "; myTextBlock.Text += "have been set on the animation's parent timeline."; myStackPanel.Children.Add(myTextBlock); Rectangle complexAutoReverseExample = new Rectangle(); complexAutoReverseExample.Name = "complexAutoReverseExample"; this.RegisterName(complexAutoReverseExample.Name, complexAutoReverseExample); complexAutoReverseExample.Width = 100; complexAutoReverseExample.Height = 20; complexAutoReverseExample.Fill = mySolidColorBrush; complexAutoReverseExample.HorizontalAlignment = HorizontalAlignment.Left; myStackPanel.Children.Add(complexAutoReverseExample); // // Create an animation that does not automatically play in reverse. // DoubleAnimation myDoubleAnimation = new DoubleAnimation(); Storyboard.SetTargetName(myDoubleAnimation, withoutAutoReverseRectangle.Name); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)); myDoubleAnimation.From = 100; myDoubleAnimation.To = 400; myDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); myDoubleAnimation.AutoReverse = false; // // Create an animation that automatically reverses at the end of each iteration. // DoubleAnimation myAutomaticallyReversedDoubleAnimation = new DoubleAnimation(); Storyboard.SetTargetName(myAutomaticallyReversedDoubleAnimation, autoReverseRectangle.Name); Storyboard.SetTargetProperty(myAutomaticallyReversedDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)); myAutomaticallyReversedDoubleAnimation.From = 100; myAutomaticallyReversedDoubleAnimation.To = 400; myAutomaticallyReversedDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); myAutomaticallyReversedDoubleAnimation.AutoReverse = true; // // Create an animation that automatically reverses at the end of each iteration. // Set the animation to repeat twice. As // a result, then animation plays forward, then backward, then forward, and then backward again. DoubleAnimation myRepeatedAndReversedDoubleAnimation = new DoubleAnimation(); Storyboard.SetTargetName(myRepeatedAndReversedDoubleAnimation, autoReverseRectangleWithRepeats.Name); Storyboard.SetTargetProperty(myRepeatedAndReversedDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)); myRepeatedAndReversedDoubleAnimation.From = 100; myRepeatedAndReversedDoubleAnimation.To = 400; myRepeatedAndReversedDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); myRepeatedAndReversedDoubleAnimation.AutoReverse = true; myRepeatedAndReversedDoubleAnimation.RepeatBehavior = new RepeatBehavior(2); // // Set the parent timeline's AutoReverse property to True and set the animation's // RepeatBehavior to 2x. As a result, the animation plays forward twice and then backwards twice. // ParallelTimeline myParallelTimeline = new ParallelTimeline(); myParallelTimeline.AutoReverse = true; DoubleAnimation myParallelRepeatedAndReversedDoubleAnimation = new DoubleAnimation(); Storyboard.SetTargetName(myParallelRepeatedAndReversedDoubleAnimation, complexAutoReverseExample.Name); Storyboard.SetTargetProperty(myParallelRepeatedAndReversedDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)); myParallelRepeatedAndReversedDoubleAnimation.From = 100; myParallelRepeatedAndReversedDoubleAnimation.To = 400; myParallelRepeatedAndReversedDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); myParallelRepeatedAndReversedDoubleAnimation.AutoReverse = true; myParallelRepeatedAndReversedDoubleAnimation.RepeatBehavior = new RepeatBehavior(2); // // Create a Storyboard to contain the animations and add the animations to the Storyboard // Storyboard myStoryboard = new Storyboard(); myStoryboard.Children.Add(myDoubleAnimation); myStoryboard.Children.Add(myAutomaticallyReversedDoubleAnimation); myStoryboard.Children.Add(myRepeatedAndReversedDoubleAnimation); myParallelTimeline.Children.Add(myParallelRepeatedAndReversedDoubleAnimation); myStoryboard.Children.Add(myParallelTimeline); // // Create the button to restart the animations. // Button myButton = new Button(); myButton.Margin = new Thickness(0, 30, 0, 0); myButton.HorizontalAlignment = HorizontalAlignment.Left; myButton.Content = "Restart Animations"; myStackPanel.Children.Add(myButton); // // Create an EventTrigger and a BeginStoryboard action to start // the storyboard BeginStoryboard myBeginStoryboard = new BeginStoryboard(); myBeginStoryboard.Storyboard = myStoryboard; EventTrigger myEventTrigger = new EventTrigger(); myEventTrigger.RoutedEvent = Button.ClickEvent; myEventTrigger.SourceName = myButton.Name; myEventTrigger.Actions.Add(myBeginStoryboard); myStackPanel.Triggers.Add(myEventTrigger); this.Content = myStackPanel; }
const int unitspan = 30; //日时间片 void initAni() { timeline.txtRad.Text = "速度:" + sb.SpeedRatio.ToString("f1"); var l = from e1 in root.earth.objManager.getObjList().Where(p => p.busiData != null && p.busiData.busiAddition != null) from e2 in (e1.busiData.busiAddition as evolveDatas).datas select new { d = e2.zDate }; if (l.Count() == 0) { return; } StartDate = (DateTime)l.Min(p => p.d); EndDate = (DateTime)l.Max(p => p.d); var l2 = from e1 in root.earth.objManager.getObjList().Where(p => p.busiData != null && p.busiData.busiAddition != null) from e2 in (e1.busiData.busiAddition as evolveDatas).datas select new { argu = e2.evoType.ToString(), date = e2.zDate, fromid = e2.FromId, etype = e2.evoType, obj = e1 }; int idx = 0; foreach (var item in l2.OrderBy(p => p.date)) //处理边上列表 { EventInfo ei = new EventInfo() { idx = idx, background = Brushes.Transparent, eventType = item.etype, visibility = Visibility.Collapsed, objName = item.obj.name, //center = item.obj.center, eventDate = (DateTime)item.date, fromid = item.fromid, obj = item.obj, info = "其它信息" }; eventInfoes.Add(ei); idx++; } lstInfo.ItemsSource = eventInfoes; ParallelTimeline ptl; int starttick; foreach (EventInfo item in eventInfoes) { starttick = ((int)((DateTime)item.eventDate - StartDate).TotalDays) * unitspan; ptl = new ParallelTimeline() { BeginTime = new TimeSpan(0, 0, 0, 0, starttick) }; sb.Children.Add(ptl); switch (item.eventType) { case EevoType.新建: if (item.obj is pSymbolObject) { DoubleAnimation ani = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(6 * 30 * unitspan), FillBehavior.HoldEnd); Storyboard.SetTarget(ani, item.obj); Storyboard.SetTargetProperty(ani, new PropertyPath(PowerBasicObject.ProgressProperty)); ptl.Children.Add(ani); ptl.CurrentStateInvalidated += new EventHandler(ptl_CurrentStateInvalidated); ptl.SetValue(ToolTipService.ToolTipProperty, item.idx); } else if (item.obj is pPowerLine) { DoubleAnimation ani = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(6 * 30 * unitspan), FillBehavior.HoldEnd); Storyboard.SetTarget(ani, item.obj); Storyboard.SetTargetProperty(ani, new PropertyPath(PowerBasicObject.ProgressProperty)); ptl.Children.Add(ani); ptl.CurrentStateInvalidated += new EventHandler(ptl_CurrentStateInvalidated); ptl.SetValue(ToolTipService.ToolTipProperty, item.idx); //(item.obj as zMapPolyline).aniType = MyControlLibrary.DevMap.EAniType.绘制; } break; case EevoType.改建: //改建失效 if (item.obj is pSymbolObject) { } else if (item.obj is pPowerLine) { } break; case EevoType.退运: //退运 if (item.obj is pSymbolObject) { DoubleAnimation ani = new DoubleAnimation(1, 0.5, TimeSpan.FromMilliseconds(6 * 30 * unitspan), FillBehavior.HoldEnd); Storyboard.SetTarget(ani, item.obj); Storyboard.SetTargetProperty(ani, new PropertyPath(PowerBasicObject.ProgressProperty)); ptl.Children.Add(ani); ptl.CurrentStateInvalidated += new EventHandler(ptl_CurrentStateInvalidated); ptl.SetValue(ToolTipService.ToolTipProperty, item.idx); } else if (item.obj is pPowerLine) { DoubleAnimation ani = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(6 * 30 * unitspan), FillBehavior.HoldEnd); Storyboard.SetTarget(ani, item.obj); Storyboard.SetTargetProperty(ani, new PropertyPath(PowerBasicObject.ProgressProperty)); ptl.Children.Add(ani); ptl.CurrentStateInvalidated += new EventHandler(ptl_CurrentStateInvalidated); ptl.SetValue(ToolTipService.ToolTipProperty, item.idx); //(item.obj as zMapPolyline).aniType = MyControlLibrary.DevMap.EAniType.擦除; } break; } } }