public RepeatBehavior(Duration duration)
    {
      if (duration == null)
      {
        throw new ArgumentNullException("duration");
      }

      _iterationCount = 0;
      _duration = duration;
    }
Beispiel #2
0
        // Inits or resets an opacity animation used to make the caret blink. 
        private void SetBlinkAnimation(bool visible, bool positionChanged) 
        {
            if (!_isBlinkEnabled) 
            {
                return;
            }
 
            // NB: "Blink" is the period of time between successive
            // state changes in the caret animation.  "Flash" is 
            // 2 * blink, the period of time to transition from 
            // visible, to hidden, to visible again.
            int blinkInterval = Win32GetCaretBlinkTime(); 
            if (blinkInterval > 0) // -1 if the caret shouldn't blink.
            {
                Duration blinkDuration = new Duration(TimeSpan.FromMilliseconds(blinkInterval * 2));
 
                if (_blinkAnimationClock == null || _blinkAnimationClock.Timeline.Duration != blinkDuration)
                { 
                    DoubleAnimationUsingKeyFrames blinkAnimation = new DoubleAnimationUsingKeyFrames(); 
                    blinkAnimation.BeginTime = null;
                    blinkAnimation.RepeatBehavior = RepeatBehavior.Forever; 
                    blinkAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromPercent(0.0)));
                    blinkAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromPercent(0.5)));
                    blinkAnimation.Duration = blinkDuration;
 
                    _blinkAnimationClock = blinkAnimation.CreateClock();
                    _blinkAnimationClock.Controller.Begin(); 
 
                    _caretElement.ApplyAnimationClock(UIElement.OpacityProperty, _blinkAnimationClock);
                } 
            }
            else if (_blinkAnimationClock != null)
            {
                // No blink (control panel option). 
                _caretElement.ApplyAnimationClock(UIElement.OpacityProperty, null);
                _blinkAnimationClock = null; 
            } 

            if (_blinkAnimationClock != null) 
            {
                // Disable the animation when the caret isn't rendered
                // to get better perf.
                if (visible && (!(_blinkAnimationClock.CurrentState == ClockState.Active) || positionChanged)) 
                {
                    // Start the blinking animation for caret 
                    _blinkAnimationClock.Controller.Begin(); 
                }
                else if (!visible) 
                {
                    // Stop the blinking animation if the caret isn't visible even we start it yet.
                    // Because ApplyAnimationClock() calling can start the animation without
                    // the calling of Begin() which case is the auto selection(with DatePicker). 
                    _blinkAnimationClock.Controller.Stop();
                } 
            } 
        }
Beispiel #3
0
 public Animation(double duration, int StartValue, int StopValue)
 {
   _duration = new Duration(duration);
   _start = StartValue;
   _stop = StopValue;
 }
Beispiel #4
0
        // 


        internal static void RestoreStoryboardDuration(Storyboard storyboard, Duration? duration) 
        { 
            Debug.Assert(storyboard != null);
            if (duration != null) 
            {
                foreach (Timeline timeline in storyboard.Children)
                { 
                    timeline.Duration = (Duration)duration;
                }
            } 
        } 
Beispiel #5
0
        //

 

        internal static Duration? ResetStoryboardDuration(Storyboard storyboard)
        { 
            Debug.Assert(storyboard != null); 
            if (storyboard.Children.Count > 0)
            { 
                Duration nullDuration = new Duration(new TimeSpan(0, 0, 0, 0));
                Duration duration = storyboard.Children[0].Duration;
                foreach (Timeline timeline in storyboard.Children) 
                {
                    timeline.Duration = nullDuration;
                } 
                return duration; 
            }
            return null; 
        }
 internal override void ComputeCurrentFillInterval(TimeIntervalCollection parentIntervalCollection,
                                                   TimeSpan beginTime, TimeSpan endTime, Duration period,
                                                   double appliedSpeedRatio, double accelRatio, double decelRatio,
                                                   bool isAutoReversed)
 {
     _currentIntervals.Clear();
     parentIntervalCollection.ProjectPostFillZone(ref _currentIntervals,
                                                  beginTime, endTime,
                                                  period, appliedSpeedRatio,
                                                  accelRatio, decelRatio, isAutoReversed);
 }
 internal override void ComputeCurrentIntervals(TimeIntervalCollection parentIntervalCollection,
                                                TimeSpan beginTime, TimeSpan? endTime,
                                                Duration fillDuration, Duration period,
                                                double appliedSpeedRatio, double accelRatio, double decelRatio,
                                                bool isAutoReversed)
 {
     _currentIntervals.Clear();
     parentIntervalCollection.ProjectOntoPeriodicFunction(ref _currentIntervals,
                                                          beginTime, endTime,
                                                          fillDuration, period, appliedSpeedRatio,
                                                          accelRatio, decelRatio, isAutoReversed);
 }
Beispiel #8
0
 public SingleAnimation(float fromValue, float toValue, Duration duration)
 {
 }
Beispiel #9
0
 /// <summary>
 /// Creates a new ByteAnimation that will animate a
 /// Byte property from its base value to the value specified
 /// by the "toValue" parameter of this constructor.
 /// </summary>
 public ByteAnimation(Byte toValue, Duration duration)
     : this()
 {
     To       = toValue;
     Duration = duration;
 }
Beispiel #10
0
 /// <summary>
 /// Creates a ParallelTimeline with the specified begin time and duration.
 /// </summary>
 /// <param name="beginTime">
 /// The scheduled BeginTime for this ParallelTimeline.
 /// </param>
 /// <param name="duration">
 /// The simple Duration of this ParallelTimeline.
 /// </param>
 public ParallelTimeline(TimeSpan?beginTime, Duration duration)
     : base(beginTime, duration)
 {
 }
Beispiel #11
0
 /// <summary>
 /// Creates a ParallelTimeline with the specified BeginTime, Duration and RepeatBehavior.
 /// </summary>
 /// <param name="beginTime">
 /// The scheduled BeginTime for this ParallelTimeline.
 /// </param>
 /// <param name="duration">
 /// The simple Duration of this ParallelTimeline.
 /// </param>
 /// <param name="repeatBehavior">
 /// The RepeatBehavior for this ParallelTimeline.
 /// </param>
 public ParallelTimeline(TimeSpan?beginTime, Duration duration, RepeatBehavior repeatBehavior)
     : base(beginTime, duration, repeatBehavior)
 {
 }
Beispiel #12
0
 /// <summary>
 /// Creates a new RectAnimation that will animate a
 /// Rect property from its base value to the value specified
 /// by the "toValue" parameter of this constructor.
 /// </summary>
 public RectAnimation(Rect toValue, Duration duration)
     : this()
 {
     To       = toValue;
     Duration = duration;
 }
Beispiel #13
0
        private void ResolveKeyTimes()
        {
            Debug.Assert(!_areKeyTimesValid, "KeyFramePoint3DAnimaton.ResolveKeyTimes() shouldn't be called if the key times are already valid.");

            int keyFrameCount = 0;

            if (_keyFrames != null)
            {
                keyFrameCount = _keyFrames.Count;
            }

            if (keyFrameCount == 0)
            {
                _sortedResolvedKeyFrames = null;
                _areKeyTimesValid        = true;
                return;
            }

            _sortedResolvedKeyFrames = new ResolvedKeyFrameEntry[keyFrameCount];

            int index = 0;

            // Initialize the _originalKeyFrameIndex.
            for ( ; index < keyFrameCount; index++)
            {
                _sortedResolvedKeyFrames[index]._originalKeyFrameIndex = index;
            }

            // calculationDuration represents the time span we will use to resolve
            // percent key times. This is defined as the value in the following
            // precedence order:
            //   1. The animation's duration, but only if it is a time span, not auto or forever.
            //   2. The largest time span specified key time of all the key frames.
            //   3. 1 second, to match the From/To/By animations.

            TimeSpan calculationDuration = TimeSpan.Zero;

            Duration duration = Duration;

            if (duration.HasTimeSpan)
            {
                calculationDuration = duration.TimeSpan;
            }
            else
            {
                calculationDuration = LargestTimeSpanKeyTime;
            }

            int       maxKeyFrameIndex  = keyFrameCount - 1;
            ArrayList unspecifiedBlocks = new ArrayList();
            bool      hasPacedKeyTimes  = false;

            //
            // Pass 1: Resolve Percent and Time key times.
            //

            index = 0;
            while (index < keyFrameCount)
            {
                KeyTime keyTime = _keyFrames[index].KeyTime;

                switch (keyTime.Type)
                {
                case KeyTimeType.Percent:

                    _sortedResolvedKeyFrames[index]._resolvedKeyTime = TimeSpan.FromMilliseconds(
                        keyTime.Percent * calculationDuration.TotalMilliseconds);
                    index++;
                    break;

                case KeyTimeType.TimeSpan:

                    _sortedResolvedKeyFrames[index]._resolvedKeyTime = keyTime.TimeSpan;

                    index++;
                    break;

                case KeyTimeType.Paced:
                case KeyTimeType.Uniform:

                    if (index == maxKeyFrameIndex)
                    {
                        // If the last key frame doesn't have a specific time
                        // associated with it its resolved key time will be
                        // set to the calculationDuration, which is the
                        // defined in the comments above where it is set.
                        // Reason: We only want extra time at the end of the
                        // key frames if the user specifically states that
                        // the last key frame ends before the animation ends.

                        _sortedResolvedKeyFrames[index]._resolvedKeyTime = calculationDuration;
                        index++;
                    }
                    else if (index == 0 &&
                             keyTime.Type == KeyTimeType.Paced)
                    {
                        // Note: It's important that this block come after
                        // the previous if block because of rule precendence.

                        // If the first key frame in a multi-frame key frame
                        // collection is paced, we set its resolved key time
                        // to 0.0 for performance reasons.  If we didn't, the
                        // resolved key time list would be dependent on the
                        // base value which can change every animation frame
                        // in many cases.

                        _sortedResolvedKeyFrames[index]._resolvedKeyTime = TimeSpan.Zero;
                        index++;
                    }
                    else
                    {
                        if (keyTime.Type == KeyTimeType.Paced)
                        {
                            hasPacedKeyTimes = true;
                        }

                        KeyTimeBlock block = new KeyTimeBlock();
                        block.BeginIndex = index;

                        // NOTE: We don't want to go all the way up to the
                        // last frame because if it is Uniform or Paced its
                        // resolved key time will be set to the calculation
                        // duration using the logic above.
                        //
                        // This is why the logic is:
                        //    ((++index) < maxKeyFrameIndex)
                        // instead of:
                        //    ((++index) < keyFrameCount)

                        while ((++index) < maxKeyFrameIndex)
                        {
                            KeyTimeType type = _keyFrames[index].KeyTime.Type;

                            if (type == KeyTimeType.Percent ||
                                type == KeyTimeType.TimeSpan)
                            {
                                break;
                            }
                            else if (type == KeyTimeType.Paced)
                            {
                                hasPacedKeyTimes = true;
                            }
                        }

                        Debug.Assert(index < keyFrameCount,
                                     "The end index for a block of unspecified key frames is out of bounds.");

                        block.EndIndex = index;
                        unspecifiedBlocks.Add(block);
                    }

                    break;
                }
            }

            //
            // Pass 2: Resolve Uniform key times.
            //

            for (int j = 0; j < unspecifiedBlocks.Count; j++)
            {
                KeyTimeBlock block = (KeyTimeBlock)unspecifiedBlocks[j];

                TimeSpan blockBeginTime = TimeSpan.Zero;

                if (block.BeginIndex > 0)
                {
                    blockBeginTime = _sortedResolvedKeyFrames[block.BeginIndex - 1]._resolvedKeyTime;
                }

                // The number of segments is equal to the number of key
                // frames we're working on plus 1.  Think about the case
                // where we're working on a single key frame.  There's a
                // segment before it and a segment after it.
                //
                //  Time known         Uniform           Time known
                //  ^                  ^                 ^
                //  |                  |                 |
                //  |   (segment 1)    |   (segment 2)   |

                Int64    segmentCount    = (block.EndIndex - block.BeginIndex) + 1;
                TimeSpan uniformTimeStep = TimeSpan.FromTicks((_sortedResolvedKeyFrames[block.EndIndex]._resolvedKeyTime - blockBeginTime).Ticks / segmentCount);

                index = block.BeginIndex;
                TimeSpan resolvedTime = blockBeginTime + uniformTimeStep;

                while (index < block.EndIndex)
                {
                    _sortedResolvedKeyFrames[index]._resolvedKeyTime = resolvedTime;

                    resolvedTime += uniformTimeStep;
                    index++;
                }
            }

            //
            // Pass 3: Resolve Paced key times.
            //

            if (hasPacedKeyTimes)
            {
                ResolvePacedKeyTimes();
            }

            //
            // Sort resolved key frame entries.
            //

            Array.Sort(_sortedResolvedKeyFrames);

            _areKeyTimesValid = true;
            return;
        }
Beispiel #14
0
 public SingleAnimation(float fromValue, float tovalue, Duration duration, FillBehavior fillBehavior)
 {
 }
 /// <summary>
 /// Creates a TimelineGroup with the specified begin time and duration.
 /// </summary>
 /// <param name="beginTime">
 /// The scheduled BeginTime for this TimelineGroup.
 /// </param>
 /// <param name="duration">
 /// The simple Duration of this TimelineGroup.
 /// </param>
 protected TimelineGroup(Nullable<TimeSpan> beginTime, Duration duration)
     : base(beginTime, duration)
 {
 }
        /// <summary>
        /// Scroll the desired element into the ScrollViewer's viewport.
        /// </summary>
        /// <param name="viewer">The ScrollViewer.</param>
        /// <param name="element">The element to scroll into view.</param>
        /// <param name="horizontalMargin">The margin to add on the left or right.
        /// </param>
        /// <param name="verticalMargin">The margin to add on the top or bottom.
        /// </param>
        /// <param name="duration">The duration of the animation.</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="viewer" /> is null.
        /// </exception>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="element" /> is null.
        /// </exception>
        public static void ScrollIntoView(this ScrollViewer viewer, FrameworkElement element, double horizontalMargin, double verticalMargin, Duration duration)
        {
            if (viewer == null)
            {
                throw new ArgumentNullException("viewer");
            }
            else if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            // Get the position of the element relative to the ScrollHost
            Rect? itemRect = element.GetBoundsRelativeTo(viewer);
            if (itemRect == null)
            {
                return;
            }

            // Scroll vertically
            double verticalOffset = viewer.VerticalOffset;
            double verticalDelta = 0;
            double hostBottom = viewer.ViewportHeight;
            double itemBottom = itemRect.Value.Bottom + verticalMargin;
            if (hostBottom < itemBottom)
            {
                verticalDelta = itemBottom - hostBottom;
                verticalOffset += verticalDelta;
            }
            double itemTop = itemRect.Value.Top - verticalMargin;
            if (itemTop - verticalDelta < 0)
            {
                verticalOffset -= verticalDelta - itemTop;
            }

            // Scroll horizontally
            double horizontalOffset = viewer.HorizontalOffset;
            double horizontalDelta = 0;
            double hostRight = viewer.ViewportWidth;
            double itemRight = itemRect.Value.Right + horizontalMargin;
            if (hostRight < itemRight)
            {
                horizontalDelta = itemRight - hostRight;
                horizontalOffset += horizontalDelta;
            }
            double itemLeft = itemRect.Value.Left - horizontalMargin;
            if (itemLeft - horizontalDelta < 0)
            {
                horizontalOffset -= horizontalDelta - itemLeft;
            }

            if (duration == TimeSpan.Zero)
            {
                viewer.ScrollToVerticalOffset(verticalOffset);
                viewer.ScrollToHorizontalOffset(horizontalOffset);
            }
            else
            {
                Storyboard storyboard = new Storyboard();
                SetVerticalOffset(viewer, viewer.VerticalOffset);
                SetHorizontalOffset(viewer, viewer.HorizontalOffset);

                DoubleAnimation verticalOffsetAnimation = new DoubleAnimation { To = verticalOffset, Duration = duration };
                DoubleAnimation horizontalOffsetAnimation = new DoubleAnimation { To = verticalOffset, Duration = duration };

                Storyboard.SetTarget(verticalOffsetAnimation, viewer);
                Storyboard.SetTarget(horizontalOffsetAnimation, viewer);
                Storyboard.SetTargetProperty(horizontalOffsetAnimation, new PropertyPath(ScrollViewerExtensions.HorizontalOffsetProperty));
                Storyboard.SetTargetProperty(verticalOffsetAnimation, new PropertyPath(ScrollViewerExtensions.VerticalOffsetProperty));

                storyboard.Children.Add(verticalOffsetAnimation);
                storyboard.Children.Add(horizontalOffsetAnimation);

                storyboard.Begin();
            }
        }
 /// <summary>
 /// Creates a TimelineGroup with the specified BeginTime, Duration and RepeatBehavior.
 /// </summary>
 /// <param name="beginTime">
 /// The scheduled BeginTime for this TimelineGroup.
 /// </param>
 /// <param name="duration">
 /// The simple Duration of this TimelineGroup.
 /// </param>
 /// <param name="repeatBehavior">
 /// The RepeatBehavior for this TimelineGroup.
 /// </param>
 protected TimelineGroup(Nullable<TimeSpan> beginTime, Duration duration, RepeatBehavior repeatBehavior)
     : base(beginTime, duration, repeatBehavior)
 {
 }
Beispiel #18
0
 /// <summary>
 /// Creates a new DoubleAnimation that will animate a
 /// Double property from its base value to the value specified
 /// by the "toValue" parameter of this constructor.
 /// </summary>
 public DoubleAnimation(Double toValue, Duration duration)
     : this()
 {
     To       = toValue;
     Duration = duration;
 }