Exemple #1
0
        public void Start()
        {
            if (state != State.Stopped)
            {
                Stop();
            }

            state = State.Pending;

            cancellationToken = Window.SetTimeout(() =>
            {
                if (state != State.Pending)
                {
                    return;
                }

                state = State.Running;

                string currentValue            = valueBounds.FormattedStartValue;
                TransitionTiming currentTiming = timing;

                if (continuationMode == ContinuationMode.ContinueValue || continuationMode == ContinuationMode.ContinueValueAndTime)
                {
                    currentValue = WindowExtensions.GetComputedStyle(targetElement).GetPropertyValue(targetProperty);
                }

                if (continuationMode == ContinuationMode.ContinueValueAndTime)
                {
                    double currentProgress       = valueBounds.GetProgress(currentValue);
                    double currentProgressTiming = timing.Timing.GetTiming(currentProgress);

                    currentTiming = timing.AddDuration((int)(-currentProgressTiming * timing.Duration)); // also, a truncated timing curve is needed here;
                }

                targetElement.Style.GetTransitionDictionary().Clear(targetProperty);
                targetElement.Style[targetProperty] = currentValue;

                RunAsync(() =>
                {
                    if (state == State.Running)
                    {
                        targetElement.Style.GetTransitionDictionary().Set(targetProperty, currentTiming.ToString());
                        targetElement.Style[targetProperty] = valueBounds.FormattedEndValue;
                    }
                });

                Window.SetTimeout(() =>
                {
                    if (state == State.Running)
                    {
                        RaiseCompleted();
                    }
                }, currentTiming.Delay + currentTiming.Duration);
            }, delay);
        }
Exemple #2
0
        public void Stop()
        {
            if (state == State.Stopped)
            {
                return;
            }

            if (state == State.Pending)
            {
                Window.ClearTimeout(cancellationToken);
            }
            else if (state == State.Running)
            {
                string currentValue = WindowExtensions.GetComputedStyle(targetElement).GetPropertyValue(targetProperty);
                targetElement.Style.GetTransitionDictionary().Clear(targetProperty);
                targetElement.Style[targetProperty] = currentValue;
            }
            else
            {
                throw new Exception("Unsupported animation state");
            }

            state = State.Stopped;
        }