コード例 #1
0
        public bool GoToState(VisualState state, bool useTransitions)
        {
            if (state == CurrentState)
            {
                return(true);
            }

            string           currentStateName     = CurrentState != null ? CurrentState.Name : String.Empty;
            VisualTransition transition           = useTransitions ? GetTransition(Transitions, currentStateName, state.Name) : null;
            Storyboard       transitionStoryboard = transition != null ? transition.Storyboard : null;

            Storyboard storyboard;

            if (transitionStoryboard != null && state.Storyboard != null)
            {
                // create a sequential animation with the transition storyboard first and then the state storyboard
                SequentialTimeline sequentialTimeline = new SequentialTimeline();
                sequentialTimeline.Children.Add(transitionStoryboard);
                sequentialTimeline.Children.Add(state.Storyboard);

                storyboard = new Storyboard();
                storyboard.Children.Add(sequentialTimeline);
            }
            else
            {
                storyboard = transitionStoryboard ?? state.Storyboard;
            }

            StartNewStoryboard(storyboard);

            CurrentState = state;
            return(true);
        }
コード例 #2
0
        public void SequentialTimelineClockStoryboardTest()
        {
            DoubleAnimation animation1 = new DoubleAnimation {
                To = 100, Duration = new Duration(TimeSpan.FromSeconds(1))
            };
            DoubleAnimation animation2 = new DoubleAnimation {
                To = 200, Duration = new Duration(TimeSpan.FromSeconds(0))
            };
            DoubleAnimation animation3 = new DoubleAnimation {
                To = 300, Duration = new Duration(TimeSpan.FromSeconds(1))
            };

            SequentialTimeline sequentialTimeline = new SequentialTimeline();

            sequentialTimeline.Children.Add(animation1);
            sequentialTimeline.Children.Add(animation2);
            sequentialTimeline.Children.Add(animation3);

            Storyboard storyboard = new Storyboard();

            storyboard.Children.Add(sequentialTimeline);

            FrameworkElement element = new FrameworkElement {
                Width = 0, Height = 0
            };

            Storyboard.SetTarget(animation1, element);
            Storyboard.SetTargetProperty(animation1, PropertyPath.FromDependencyProperty(FrameworkElement.WidthProperty));

            Storyboard.SetTarget(animation2, element);
            Storyboard.SetTargetProperty(animation2, PropertyPath.FromDependencyProperty(FrameworkElement.WidthProperty));

            Storyboard.SetTarget(animation3, element);
            Storyboard.SetTargetProperty(animation3, PropertyPath.FromDependencyProperty(FrameworkElement.WidthProperty));

            TestRootClock rootClock = new TestRootClock();

            element.SetAnimatableRootClock(new AnimatableRootClock(rootClock, true));
            storyboard.Begin(element);

            rootClock.Tick(TimeSpan.FromSeconds(0));
            Assert.AreEqual(0, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(0.9));
            Assert.AreEqual(90, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(1));
            Assert.AreEqual(200, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(1.5));
            Assert.AreEqual(250, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(2));
            Assert.AreEqual(300, element.Width);
        }
コード例 #3
0
        public object Load(IContentManager contentManager)
        {
            Type propertyTimelineType = Type.GetType(PropertyTimelineType);

            float inverseDuration = 1.0f / Duration;

            //for (int i = 0; i < _keyFrames.Count; i++)
            //{
            //    _keyFrames[i].Time *= inverseDuration;
            //}

            if (KeyFrames.Count > 1)
            {
                List <SequentialTimeline> timelines = new List <SequentialTimeline>();

                SequentialTimeline sequentialTimeline = new SequentialTimeline();
                sequentialTimeline.BeginTime = 0;
                sequentialTimeline.EndTime   = 1;
                sequentialTimeline.Duration  = 1;

                timelines.Add(sequentialTimeline);

                //masterTimeline.Children.Add(sequentialTimeline);

                IPropertyTimeline previous = null;
                for (int i = 1; i < KeyFrames.Count; i++)
                {
                    //if (_keyFrames[i].FillBehavior == KeyFrameFillBehavior.BeginNewTimeline)
                    //{
                    //    sequentialTimeline.EndTime = KeyFrames[i].Time;


                    //    sequentialTimeline = new SequentialTimeline();
                    //    sequentialTimeline.BeginTime = KeyFrames[i].Time;

                    //    masterTimeline.Children.Add(sequentialTimeline);
                    //}
                    //else
                    //{
                    IPropertyTimeline propertyTimeline = (IPropertyTimeline)Activator.CreateInstance(propertyTimelineType);

                    propertyTimeline.TargetName = TargetName;

                    propertyTimeline.EasingFunction = KeyFrames[i - 1].EasingFunction;
                    propertyTimeline.BeginTime      = KeyFrames[i - 1].Time * inverseDuration;
                    propertyTimeline.EndTime        = 1;
                    propertyTimeline.Duration       = KeyFrames[i].Time * inverseDuration - propertyTimeline.BeginTime;
                    propertyTimeline.FillBehavior   = (FillBehavior)KeyFrames[i].FillBehavior;

                    if (previous != null)
                    {
                        previous.EndTime = propertyTimeline.BeginTime;
                    }

                    propertyTimelineType.GetProperty("From").SetValue(propertyTimeline, KeyFrames[i - 1].Value, null);
                    propertyTimelineType.GetProperty("To").SetValue(propertyTimeline, KeyFrames[i].Value, null);

                    sequentialTimeline.Children.Add(propertyTimeline);
                    //sequentialTimeline.Duration = KeyFrames[i].Time;

                    previous = propertyTimeline;
                    //}
                }

                return(sequentialTimeline);
            }
            else
            {
                IPropertyTimeline propertyTimeline = (IPropertyTimeline)Activator.CreateInstance(propertyTimelineType);
                propertyTimeline.TargetName = TargetName;
                propertyTimeline.BeginTime  = 0;
                propertyTimeline.EndTime    = 1;
                propertyTimeline.Duration   = 1;

                propertyTimeline.EasingFunction = new LinearEase();

                if (KeyFrames.Count > 0)
                {
                    propertyTimelineType.GetProperty("From").SetValue(propertyTimeline, KeyFrames[0].Value, null);
                    propertyTimelineType.GetProperty("To").SetValue(propertyTimeline, KeyFrames[0].Value, null);
                }

                return(propertyTimeline);
            }
        }