Ejemplo n.º 1
0
        //


        internal override void Seal()
        {
            if (!IsSealed)
            {
                // Gets our Storyboard value.  This value may have come from a
                //  ResourceReferenceExpression or might have been a deferred
                //  reference that has since been realized.
                Storyboard snapshot = GetValue(StoryboardProperty) as Storyboard;

                if (snapshot == null)
                {
                    // This is the same error thrown by Begin if the Storyboard
                    //  property couldn't be resolved at Begin time.  Since we're
                    //  not allowing changes after this point, lack of resolution
                    //  here means the same thing.
                    throw new InvalidOperationException(SR.Get(SRID.Storyboard_StoryboardReferenceRequired));
                }

                // We're planning to break our thread affinity - we also need to
                //  make sure the Storyboard can also be used accross threads.
                if (!snapshot.CanFreeze)
                {
                    throw new InvalidOperationException(SR.Get(SRID.Storyboard_UnableToFreeze));
                }
                if (!snapshot.IsFrozen)
                {
                    snapshot.Freeze();
                }

                // Promote that snapshot into a local value.  This is a no-op if it
                //  was a deferred reference or local Storyboard, but if it came from a
                //  ResourceReferenceExpression it will replace the Expression object
                //  with a snapshot of its current value.
                Storyboard = snapshot;
            }
            else
            {
                ; // base.Seal() will throw exception for us if already sealed.
            }

            base.Seal();

            // Now we can break our thread affinity
            DetachFromDispatcher();
        }
 // Token: 0x0600168B RID: 5771 RVA: 0x000704DC File Offset: 0x0006E6DC
 internal override void Seal()
 {
     if (!base.IsSealed)
     {
         Storyboard storyboard = base.GetValue(BeginStoryboard.StoryboardProperty) as Storyboard;
         if (storyboard == null)
         {
             throw new InvalidOperationException(SR.Get("Storyboard_StoryboardReferenceRequired"));
         }
         if (!storyboard.CanFreeze)
         {
             throw new InvalidOperationException(SR.Get("Storyboard_UnableToFreeze"));
         }
         if (!storyboard.IsFrozen)
         {
             storyboard.Freeze();
         }
         this.Storyboard = storyboard;
     }
     base.Seal();
     base.DetachFromDispatcher();
 }
Ejemplo n.º 3
0
        private void UpdateIndeterminateAnimation()
        {
            if ((IndeterminateAnimation == null || (IndeterminateAnimation != null && IndeterminateAnimation.Name == DefaultIndeterminateAnimationName)) && Track != null && _arc != null)
            {
                if (IndeterminateAnimation != null && IsIndeterminateAnimationRunning)
                {
                    IsIndeterminateAnimationRunning = false;
                    IndeterminateAnimation.Stop(this);
                    IndeterminateAnimation.Remove(this);
                }

                IndeterminateAnimation = new Storyboard { Name = DefaultIndeterminateAnimationName, RepeatBehavior = RepeatBehavior.Forever };

                var trackSize = Math.Min(Track.ActualWidth, Track.ActualHeight);

                var time = (trackSize * Math.PI) / 100;

                var startAngleSetValueAnimation = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(0d)));

                Storyboard.SetTarget(startAngleSetValueAnimation, _arc);
                Storyboard.SetTargetProperty(startAngleSetValueAnimation, new PropertyPath(Arc.StartAngleProperty));

                var endAngleSetValueAnimation = new DoubleAnimation(-270, new Duration(TimeSpan.FromSeconds(0d)));

                Storyboard.SetTarget(endAngleSetValueAnimation, _arc);
                Storyboard.SetTargetProperty(endAngleSetValueAnimation, new PropertyPath(Arc.EndAngleProperty));

                var startAngleAnimation = new DoubleAnimationUsingKeyFrames();
                // NOTE: Lack of contracts: DoubleAnimationUsingKeyFrames.KeyFrames is always have collection instance
                Contract.Assume(startAngleAnimation.KeyFrames != null);
                startAngleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(360, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(time))));

                Storyboard.SetTarget(startAngleAnimation, _arc);
                Storyboard.SetTargetProperty(startAngleAnimation, new PropertyPath(Arc.StartAngleProperty));

                var endAngleAnimation = new DoubleAnimationUsingKeyFrames();
                // NOTE: Lack of contracts: DoubleAnimationUsingKeyFrames.KeyFrames is always have collection instance
                Contract.Assume(endAngleAnimation.KeyFrames != null);
                endAngleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(90, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(time))));

                Storyboard.SetTarget(endAngleAnimation, _arc);
                Storyboard.SetTargetProperty(endAngleAnimation, new PropertyPath(Arc.EndAngleProperty));

                // NOTE: Lack of contracts
                Contract.Assume(IndeterminateAnimation != null);
                Contract.Assume(IndeterminateAnimation.Children != null);

                IndeterminateAnimation.Children.Add(startAngleSetValueAnimation);
                IndeterminateAnimation.Children.Add(endAngleSetValueAnimation);
                IndeterminateAnimation.Children.Add(startAngleAnimation);
                IndeterminateAnimation.Children.Add(endAngleAnimation);

                if (IndeterminateAnimation.CanFreeze)
                {
                    IndeterminateAnimation.Freeze();
                }

                if (State == ProgressState.Indeterminate && IsEnabled)
                {
                    IndeterminateAnimation.Begin(this, Template, true);
                    IsIndeterminateAnimationRunning = true;
                }
            }
        }
Ejemplo n.º 4
0
        private void UpdateBusyAnimation()
        {
            if ((BusyAnimation == null || (BusyAnimation != null && BusyAnimation.Name == DefaultBusyAnimationName)) && Track != null && _busyBar != null)
            {
                if (BusyAnimation != null && IsBusyAnimationRunning)
                {
                    IsBusyAnimationRunning = false;
                    BusyAnimation.Stop(this);
                    BusyAnimation.Remove(this);
                }

                // NOTE: Lack of contracts: Children always have collection instance
                Contract.Assume(_busyBar.Children != null);

                BusyAnimation = new Storyboard { Name = DefaultBusyAnimationName, RepeatBehavior = RepeatBehavior.Forever };

                var firstCycleAnimations = new Collection<DoubleAnimation>();
                var secondCycleAnimations = new Collection<DoubleAnimation>();

                const double time = 0.25;
                const double durationTime = time * 2;
                const double beginTimeIncrement = time / 2;
                const double shortPauseTime = time;
                const double longPauseTime = time * 1.5;
                var partMotionTime = (_busyBar.Children.Count - 1) * beginTimeIncrement + durationTime + shortPauseTime;

                var length = Math.Min(Track.ActualWidth, Track.ActualHeight) * Math.PI;

                for (var i = 0; i < _busyBar.Children.Count; i++)
                {
                    var element = (FrameworkElement)_busyBar.Children[_busyBar.Children.Count - i - 1];
                    if (element != null)
                    {
                        var elementLength = Math.Max(element.Width, element.Height);

                        var index = (_busyBar.Children.Count - 1) / 2 - i;

                        var endPosition = length / 2 + index * (elementLength * 2);
                        var endAngle = endPosition / length * 360d;

                        var duration = new Duration(TimeSpan.FromSeconds(durationTime));

                        var firstCycleAnimation =
                            new DoubleAnimation(0d, endAngle, duration) { BeginTime = TimeSpan.FromSeconds(i * beginTimeIncrement) };
                        Storyboard.SetTarget(firstCycleAnimation, element);
                        Storyboard.SetTargetProperty(firstCycleAnimation, new PropertyPath(AngleProperty));

                        var secondCycleAnimation =
                            new DoubleAnimation(0d, endAngle, duration)
                                { BeginTime = TimeSpan.FromSeconds(partMotionTime + durationTime + i * beginTimeIncrement) };
                        Storyboard.SetTarget(secondCycleAnimation, element);
                        Storyboard.SetTargetProperty(secondCycleAnimation, new PropertyPath(AngleProperty));

                        firstCycleAnimations.Add(firstCycleAnimation);
                        secondCycleAnimations.Add(secondCycleAnimation);
                    }
                }

                for (var i = 0; i < _busyBar.Children.Count; i++)
                {
                    var element = (FrameworkElement)_busyBar.Children[_busyBar.Children.Count - i - 1];
                    if (element != null)
                    {
                        var duration = new Duration(TimeSpan.FromSeconds(durationTime));

                        var firstCycleAnimation =
                            new DoubleAnimation(360d, duration) { BeginTime = TimeSpan.FromSeconds(partMotionTime + i * beginTimeIncrement) };
                        Storyboard.SetTarget(firstCycleAnimation, element);
                        Storyboard.SetTargetProperty(firstCycleAnimation, new PropertyPath(AngleProperty));

                        var secondCycleAnimation =
                            new DoubleAnimation(360d, duration)
                                { BeginTime = TimeSpan.FromSeconds(partMotionTime * 2 + durationTime + i * beginTimeIncrement) };
                        Storyboard.SetTarget(secondCycleAnimation, element);
                        Storyboard.SetTargetProperty(secondCycleAnimation, new PropertyPath(AngleProperty));

                        var moveAnimation =
                            new DoubleAnimation(-1.0, new Duration(TimeSpan.FromSeconds(0)))
                                { BeginTime = TimeSpan.FromSeconds(partMotionTime * 2 + durationTime * 2 + i * beginTimeIncrement) };
                        Storyboard.SetTarget(moveAnimation, element);
                        Storyboard.SetTargetProperty(moveAnimation, new PropertyPath(AngleProperty));

                        firstCycleAnimations.Add(firstCycleAnimation);
                        secondCycleAnimations.Add(secondCycleAnimation);
                        secondCycleAnimations.Add(moveAnimation);
                    }
                }

                BusyAnimation.Duration = new Duration(TimeSpan.FromSeconds(longPauseTime + partMotionTime * 3 + shortPauseTime * 2 + durationTime));

                // NOTE: Lack of contracts: Children always have collection instance
                Contract.Assume(BusyAnimation.Children != null);
                foreach (var animation in firstCycleAnimations)
                {
                    BusyAnimation.Children.Add(animation);
                }

                foreach (var animation in secondCycleAnimations)
                {
                    BusyAnimation.Children.Add(animation);
                }

                if (BusyAnimation.CanFreeze)
                {
                    BusyAnimation.Freeze();
                }

                if (State == ProgressState.Busy && IsEnabled)
                {
                    BusyAnimation.Begin(this, Template, true);
                    IsBusyAnimationRunning = true;
                }
            }
        }
Ejemplo n.º 5
0
        private void UpdateIndeterminateAnimation()
        {
            if ((IndeterminateAnimation == null || (IndeterminateAnimation != null && IndeterminateAnimation.Name == DefaultIndeterminateAnimationName)) && Track != null && _indicator != null)
            {
                if (IndeterminateAnimation != null && IsIndeterminateAnimationRunning)
                {
                    IsIndeterminateAnimationRunning = false;
                    IndeterminateAnimation.Stop(this);
                    IndeterminateAnimation.Remove(this);
                }

                IndeterminateAnimation = new Storyboard { Name = DefaultIndeterminateAnimationName, RepeatBehavior = RepeatBehavior.Forever };

                var indicatorSize = Orientation == Orientation.Horizontal ? _indicator.Width : _indicator.Height;

                var trackSize = Orientation == Orientation.Horizontal ? Track.ActualWidth : Track.ActualHeight;

                var time = trackSize / 100;

                var animation = new DoubleAnimationUsingKeyFrames { Duration = new Duration(TimeSpan.FromSeconds(time + 0.5)) };
                // NOTE: Lack of contracts: DoubleAnimationUsingKeyFrames.KeyFrames is always have collection instance
                Contract.Assume(animation.KeyFrames != null);
                animation.KeyFrames.Add(new DiscreteDoubleKeyFrame(-indicatorSize - 1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
                animation.KeyFrames.Add(new LinearDoubleKeyFrame(trackSize + 1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(time))));

                Storyboard.SetTarget(animation, _indicator);
                Storyboard.SetTargetProperty(animation,
                                             new PropertyPath(Orientation == Orientation.Horizontal ? Canvas.LeftProperty : Canvas.TopProperty));

                // NOTE: Lack of contracts
                Contract.Assume(IndeterminateAnimation != null);
                Contract.Assume(IndeterminateAnimation.Children != null);
                IndeterminateAnimation.Children.Add(animation);

                if (IndeterminateAnimation.CanFreeze)
                {
                    IndeterminateAnimation.Freeze();
                }

                if (State == ProgressState.Indeterminate && IsEnabled)
                {
                    IndeterminateAnimation.Begin(this, Template, true);
                    IsIndeterminateAnimationRunning = true;
                }
            }
        }
Ejemplo n.º 6
0
        private void UpdateBusyAnimation()
        {
            if ((BusyAnimation == null || (BusyAnimation != null && BusyAnimation.Name == DefaultBusyAnimationName)) && Track != null && _busyBar != null)
            {
                if (BusyAnimation != null && IsBusyAnimationRunning)
                {
                    IsBusyAnimationRunning = false;
                    BusyAnimation.Stop(this);
                    BusyAnimation.Remove(this);
                }

                // NOTE: Lack of contracts: Children always have collection instance
                Contract.Assume(_busyBar.Children != null);

                BusyAnimation = new Storyboard { Name = DefaultBusyAnimationName, RepeatBehavior = RepeatBehavior.Forever };

                const double time = 0.25;
                const double durationTime = time * 2;
                const double beginTimeIncrement = time / 2;
                const double shortPauseTime = time;
                const double longPauseTime = time * 1.5;
                var partMotionTime = (_busyBar.Children.Count - 1) * beginTimeIncrement + durationTime;

                var busyAnimations = new Collection<DoubleAnimation>();

                var width = Track.ActualWidth;
                var height = Track.ActualHeight;

                for (var i = 0; i < _busyBar.Children.Count; i++)
                {
                    var element = (FrameworkElement)_busyBar.Children[_busyBar.Children.Count - i - 1];

                    if (element != null)
                    {
                        var elementWidth = element.Width;
                        var elementHeight = element.Height;

                        var index = (_busyBar.Children.Count - 1) / 2 - i;

                        var center = (Orientation == Orientation.Horizontal ? width : height) / 2;
                        var margin = Orientation == Orientation.Horizontal ? elementWidth : elementHeight;

                        var startPosition = -(Orientation == Orientation.Horizontal ? elementWidth : elementHeight) - 1;
                        var endPosition = center + index * ((Orientation == Orientation.Horizontal ? elementWidth : elementHeight) + margin);

                        var duration = new Duration(TimeSpan.FromSeconds(durationTime));
                        var animation = new DoubleAnimation(startPosition, endPosition, duration) { BeginTime = TimeSpan.FromSeconds(i * beginTimeIncrement) };
                        Storyboard.SetTarget(animation, element);
                        Storyboard.SetTargetProperty(animation,
                                                     new PropertyPath(Orientation == Orientation.Horizontal ? Canvas.LeftProperty : Canvas.TopProperty));

                        busyAnimations.Add(animation);
                    }
                }

                for (var i = 0; i < _busyBar.Children.Count; i++)
                {
                    var element = (FrameworkElement)_busyBar.Children[_busyBar.Children.Count - i - 1];

                    if (element != null)
                    {
                        var elementWidth = element.Width;
                        var elementHeight = element.Height;

                        var endPosition = (Orientation == Orientation.Horizontal ? width : height) +
                                          (Orientation == Orientation.Horizontal ? elementWidth : elementHeight) + 1;

                        var duration = new Duration(TimeSpan.FromSeconds(durationTime));
                        var animation = new DoubleAnimation(endPosition, duration) { BeginTime = TimeSpan.FromSeconds(partMotionTime + shortPauseTime + i * beginTimeIncrement) };
                        Storyboard.SetTarget(animation, element);
                        Storyboard.SetTargetProperty(animation,
                                                     new PropertyPath(Orientation == Orientation.Horizontal ? Canvas.LeftProperty : Canvas.TopProperty));

                        busyAnimations.Add(animation);
                    }
                }

                BusyAnimation.Duration = new Duration(TimeSpan.FromSeconds(partMotionTime * 2 + shortPauseTime + longPauseTime));

                // NOTE: Lack of contracts: Children always have collection instance
                Contract.Assume(BusyAnimation.Children != null);
                foreach (var animation in busyAnimations)
                {
                    BusyAnimation.Children.Add(animation);
                }

                if (BusyAnimation.CanFreeze)
                {
                    BusyAnimation.Freeze();
                }

                if (State == ProgressState.Busy && IsEnabled)
                {
                    BusyAnimation.Begin(this, Template, true);
                    IsBusyAnimationRunning = true;
                }
            }
        }
Ejemplo n.º 7
0
        void SlideInMinimize(DockPosition dockPosition, ActionQueueCallback completeCallback)
        {
            Log.DebugFormat("SlideInMinimize {0}", dockPosition);

            //ClearAnimations();

            DoubleAnimation widthAnimation, heightAnimation, leftAnimation, topAnimation;
            Position position = CalculateSlideInPosition(dockPosition);

            // No point doing the sliding animation when the size of the window hasn't actually changed.
            if (!HasPositionChanged(position))
            {
                Log.Debug("Window size has not changed significantly, cancelling sliding animation");
                completeCallback();
                return;
            }

            Storyboard storyBoard = new Storyboard();
            storyBoard.Duration = SlideDuration;
            storyBoard.Completed += (sender, e) =>
            {
                Position minimizedPosition = new Position();
                _appbar.Resize(ref minimizedPosition);

                DispatcherHelper.UIDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                    {
                        Left = position.Left;
                        Top = position.Top;
                        Width = position.Width;
                        Height = position.Height;

                        Log.DebugFormat("SlideInMinimize Finished, MainGrid {0}", GetMainGridPosition());
                        completeCallback();
                    }));
            };

            switch (dockPosition.Selected)
            {
                case DockEdge.Left:
                    widthAnimation = CreateGridDoubleAnimation(Grid.WidthProperty);
                    widthAnimation.To = 0;
                    storyBoard.Children.Add(widthAnimation);
                    break;
                case DockEdge.Right:
                    widthAnimation = CreateGridDoubleAnimation(Grid.WidthProperty);
                    widthAnimation.To = 0;
                    storyBoard.Children.Add(widthAnimation);

                    leftAnimation = CreateGridDoubleAnimation(Canvas.LeftProperty);
                    leftAnimation.To = position.Width;
                    storyBoard.Children.Add(leftAnimation);
                    break;
                case DockEdge.Top:
                    heightAnimation = CreateGridDoubleAnimation(Grid.HeightProperty);
                    heightAnimation.To = 0;
                    storyBoard.Children.Add(heightAnimation);
                    break;
                case DockEdge.Bottom:
                    heightAnimation = CreateGridDoubleAnimation(Grid.HeightProperty);
                    heightAnimation.To = 0;
                    storyBoard.Children.Add(heightAnimation);

                    topAnimation = CreateGridDoubleAnimation(Canvas.TopProperty);
                    heightAnimation.To = position.Height;
                    storyBoard.Children.Add(topAnimation);
                    break;
            }

            storyBoard.Freeze();
            storyBoard.Begin(_mainGrid);
        }
Ejemplo n.º 8
0
        protected virtual void OnIsOpenChanged(bool oldIsOpen, bool newIsOpen)
        {
            if (newIsOpen && !oldIsOpen)
            {
                IsOpening = true;

                OnOpening(new RoutedEventArgs(OpeningEvent, this));

                if (TransitionMode == ApplicationBarTransitionMode.None)
                {
                    Mouse.Capture(this, CaptureMode.SubTree);

                    _isOpen = true;
                    InvalidateArrange();

                    OnOpened(new RoutedEventArgs(OpenedEvent, this));

                    IsOpening = false;
                }
                else
                {
                    var storyboard = new Storyboard
                                         {
                                             FillBehavior = FillBehavior.Stop
                                         };

                    Timeline animation;
                    switch (TransitionMode)
                    {
                        case ApplicationBarTransitionMode.Fade:
                            animation = new DoubleAnimation(0d, 1d, General.GetMinimumDuration(this));
                            Storyboard.SetTarget(animation, this);
                            Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));
                            // NOTE: Lack of contracts
                            Contract.Assume(storyboard.Children != null);
                            storyboard.Children.Add(animation);
                            break;
                        case ApplicationBarTransitionMode.Slide:
                            animation = new DoubleAnimation(0d, DesiredSize.Height, General.GetMinimumDuration(this));
                            Storyboard.SetTarget(animation, this);
                            Storyboard.SetTargetProperty(animation, new PropertyPath("Height"));
                            // NOTE: Lack of contracts
                            Contract.Assume(storyboard.Children != null);
                            storyboard.Children.Add(animation);
                            break;
                    }

                    storyboard.Completed += (sender, e) =>
                    {
                        storyboard.Stop(this);
                        storyboard.Remove(this);

                        OnOpened(new RoutedEventArgs(OpenedEvent, this));

                        IsOpening = false;
                    };

                    if (!StaysOpen)
                    {
                        Mouse.Capture(this, CaptureMode.SubTree);
                    }

                    storyboard.Freeze();
                    storyboard.Begin(this, true);

                    _isOpen = true;
                    InvalidateArrange();
                }
            }
            if (!newIsOpen && oldIsOpen)
            {
                IsClosing = true;

                OnClosing(new RoutedEventArgs(ClosingEvent, this));

                if (TransitionMode == ApplicationBarTransitionMode.None)
                {
                    Mouse.Capture(null);

                    _isOpen = false;
                    InvalidateArrange();

                    OnClosed(new RoutedEventArgs(ClosedEvent, this));

                    IsClosing = false;
                }
                else
                {
                    var storyboard = new Storyboard
                                         {
                                             FillBehavior = FillBehavior.Stop
                                         };

                    Timeline animation;
                    switch (TransitionMode)
                    {
                        case ApplicationBarTransitionMode.Fade:
                            animation = new DoubleAnimation(1d, 0d, General.GetMinimumDuration(this));
                            Storyboard.SetTarget(animation, this);
                            Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));
                            // NOTE: Lack of contracts
                            Contract.Assume(storyboard.Children != null);
                            storyboard.Children.Add(animation);
                            break;
                        case ApplicationBarTransitionMode.Slide:
                            animation = new DoubleAnimation(DesiredSize.Height, 0d, General.GetMinimumDuration(this));
                            Storyboard.SetTarget(animation, this);
                            Storyboard.SetTargetProperty(animation, new PropertyPath("Height"));
                            // NOTE: Lack of contracts
                            Contract.Assume(storyboard.Children != null);
                            storyboard.Children.Add(animation);
                            break;
                    }

                    storyboard.Completed += (sender, e) =>
                    {
                        storyboard.Stop(this);
                        storyboard.Remove(this);

                        if (!StaysOpen)
                        {
                            Mouse.Capture(null);
                        }

                        _isOpen = false;
                        InvalidateArrange();

                        OnClosed(new RoutedEventArgs(ClosedEvent, this));

                        IsClosing = false;
                    };

                    storyboard.Freeze();
                    storyboard.Begin(this, true);
                }
            }
        }
Ejemplo n.º 9
0
        private void Init()
        {
            storyboard = new Storyboard();
            storyboard.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
            storyboard.RepeatBehavior = RepeatBehavior.Forever;

            var animation = new DoubleAnimation();

            animation.From = 0;
            animation.To = 360;

            animation.Duration = storyboard.Duration;
            animation.RepeatBehavior = storyboard.RepeatBehavior;

            Storyboard.SetTarget(animation, canvas);
            Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"));

            storyboard.Children.Add(animation);

            animation.Freeze();
            storyboard.Freeze();
        }
 private static Storyboard CreateEmptyStoryboard()
 {
     var storyboard = new Storyboard { FillBehavior = FillBehavior.Stop };
     if (storyboard.CanFreeze)
     {
         storyboard.Freeze();
     }
     return storyboard;
 }