private static AnimationClock Animate(
            DependencyObject animatable,
            DependencyProperty prop,
            AnimationTimeline anim,
            int duration,
            double?accel,
            double?decel,
            EventHandler func)
        {
            anim.AccelerationRatio = accel.GetValueOrDefault(0.0);
            anim.DecelerationRatio = decel.GetValueOrDefault(0.0);
            anim.Duration          = (Duration)TimeSpan.FromMilliseconds((double)duration);
            anim.Freeze();
            AnimationClock animClock = anim.CreateClock();

            animClock.Completed += new EventHandler(animClock_Completed);
            if (func != null)
            {
                animClock.Completed += func;
            }
            animClock.Controller.Begin();
            Animator.ClearAnimation(animatable, prop);
            ((IAnimatable)animatable).ApplyAnimationClock(prop, animClock);
            return(animClock);

            void animClock_Completed(object sender, EventArgs e)
            {
                Animator.ClearAnimation(animatable, prop);
                // ISSUE: method pointer
                animClock.Completed -= new EventHandler((object)this, __methodptr(\u003CAnimate\u003Eg__animClock_Completed\u007C0));
            }
        }
Esempio n. 2
0
        private static AnimationClock Animate(
            DependencyObject animatable,
            DependencyProperty prop,
            AnimationTimeline anim,
            int duration,
            double?acceleration,
            double?deceleration,
            EventHandler func
            )
        {
            if (acceleration.HasValue)
            {
                anim.AccelerationRatio = acceleration.GetValueOrDefault(0);
            }

            if (deceleration.HasValue)
            {
                anim.DecelerationRatio = deceleration.GetValueOrDefault(0);
            }

            anim.Duration = TimeSpan.FromMilliseconds(duration);
            anim.Freeze();

            AnimationClock animClock = anim.CreateClock();

            // When animation is complete, remove animation and set the animation's "To"
            // value as the new value of the property.
            EventHandler eh = null;

            eh = delegate(object sender, EventArgs e)
            {
                animatable.SetValue(prop, animatable.GetValue(prop));

                ((IAnimatable)animatable).ApplyAnimationClock(prop, null);

                animClock.Completed -= eh;
            };

            animClock.Completed += eh;

            // assign completed eventHandler, if defined
            if (func != null)
            {
                animClock.Completed += func;
            }

            animClock.Controller.Begin();

            // goferit
            ((IAnimatable)animatable).ApplyAnimationClock(prop, animClock);

            return(animClock);
        }
Esempio n. 3
0
        private void ConstructAnim()
        {
            NavigationCommands.BrowseBack.InputGestures.Clear();

            _outAnimation.Completed += delegate
            {
                _isInTransition = false;
                if (_transitionTarget == BackTarget)
                {
                    GoBack();
                }
                else
                {
                    Navigate(_transitionTarget);
                }
            };
            _outAnimation.Freeze();

            _resizeAnimation.Completed += (s, e) => SizeToContent = SizeToContent.WidthAndHeight;

            Navigating += delegate(object sender, NavigatingCancelEventArgs e)
            {
                // FIX (jods): prevent further navigation when a navigation is already in progress
                //						 (e.g. double-click a button in the main menu). This would break the transitions.
                if (_isInTransition)
                {
                    e.Cancel = true;
                    return;
                }

                if (_transitionTarget != null)
                {
                    _transitionTarget = null;
                    return;
                }

                var page = Content as Page;
                if (page == null)
                {
                    return;
                }

                if (Math.Abs(_clientWidth - 0) < double.Epsilon)
                {
                    _clientWidth   = page.ActualWidth;
                    _bordersHeight = ActualHeight - page.ActualHeight;
                }
                SizeToContent = SizeToContent.Manual;

                e.Cancel          = true;
                _isInTransition   = true;
                _transitionTarget = e.NavigationMode == NavigationMode.Back ? BackTarget : e.Content;
                page.BeginAnimation(OpacityProperty, _outAnimation, HandoffBehavior.SnapshotAndReplace);
            };

            Navigated += delegate
            {
                var page = Content as Page;
                if (page == null)
                {
                    return;
                }

                if (_isFirstLoad)
                {
                    _isFirstLoad = false;
                    return;
                }

                page.Opacity = 0;
                page.Measure(new Size(_clientWidth, double.PositiveInfinity));

                _resizeAnimation.To = page.DesiredSize.Height + _bordersHeight;
                BeginAnimation(HeightProperty, _resizeAnimation);
                page.BeginAnimation(OpacityProperty, _inAnimation);
            };
        }