Example #1
0
 /// <summary>
 /// Transitions the new <see cref="T:System.Windows.UIElement"/>.
 /// </summary>
 /// <param name="newTransition">The <see cref="T:Microsoft.Phone.Controls.ITransition"/> for the new <see cref="T:System.Windows.UIElement"/>.</param>
 /// <param name="navigationInTransition">The <see cref="T:Microsoft.Phone.Controls.NavigationInTransition"/>  for the new <see cref="T:System.Windows.UIElement"/>.</param>
 private void TransitionNewElement(ITransition newTransition, NavigationInTransition navigationInTransition)
 {
     _oldContentPresenter.Visibility = Visibility.Collapsed;
     _oldContentPresenter.Content    = null;
     if (newTransition == null)
     {
         _newContentPresenter.IsHitTestVisible = true;
         _newContentPresenter.Opacity          = 1;
         return;
     }
     if (newTransition.GetCurrentState() != ClockState.Stopped)
     {
         newTransition.Stop();
     }
     newTransition.Completed += delegate
     {
         newTransition.Stop();
         _newContentPresenter.CacheMode        = null;
         _newContentPresenter.IsHitTestVisible = true;
         if (navigationInTransition != null)
         {
             navigationInTransition.OnEndTransition();
         }
     };
     Dispatcher.BeginInvoke(delegate
     {
         if (navigationInTransition != null)
         {
             navigationInTransition.OnBeginTransition();
         }
         _newContentPresenter.Opacity = 1;
         newTransition.Begin();
     });
 }
 /// <summary>
 /// This checks to make sure that, if the transition not be in the clock
 /// state of Stopped, that is will be stopped.
 /// </summary>
 /// <param name="transition">The transition instance.</param>
 private static void EnsureStoppedTransition(ITransition transition)
 {
     if (transition != null && transition.GetCurrentState() != ClockState.Stopped)
     {
         transition.Stop();
     }
 }
Example #3
0
        /// <summary>
        /// Called when the value of the
        /// <see cref="P:System.Windows.Controls.ContentControl.Content"/>
        /// property changes.
        /// </summary>
        /// <param name="oldContent">The old <see cref="T:System.Object"/>.</param>
        /// <param name="newContent">The new <see cref="T:System.Object"/>.</param>
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);
            UIElement oldElement = oldContent as UIElement;
            UIElement newElement = newContent as UIElement;

            if (_firstContentPresenter == null || _secondContentPresenter == null || newElement == null)
            {
                return;
            }
            if (_useFirstAsNew)
            {
                _newContentPresenter = _firstContentPresenter;
                _oldContentPresenter = _secondContentPresenter;
            }
            else
            {
                _newContentPresenter = _secondContentPresenter;
                _oldContentPresenter = _firstContentPresenter;
            }
            _useFirstAsNew = !_useFirstAsNew;
            NavigationOutTransition navigationOutTransition = null;
            NavigationInTransition  navigationInTransition  = null;
            ITransition             oldTransition           = null;
            ITransition             newTransition           = null;

            if (oldElement != null)
            {
                navigationOutTransition = TransitionService.GetNavigationOutTransition(oldElement);
                TransitionElement oldTransitionElement = null;
                if (navigationOutTransition != null)
                {
                    oldTransitionElement = _isForwardNavigation ? navigationOutTransition.Forward : navigationOutTransition.Backward;
                }
                if (oldTransitionElement != null)
                {
                    oldTransition = oldTransitionElement.GetTransition(oldElement);
                    _oldContentPresenter.CacheMode        = new BitmapCache();
                    _oldContentPresenter.IsHitTestVisible = false;
                }
            }
            if (newElement != null)
            {
                navigationInTransition = TransitionService.GetNavigationInTransition(newElement);
                TransitionElement newTransitionElement = null;
                if (navigationInTransition != null)
                {
                    newTransitionElement = _isForwardNavigation ? navigationInTransition.Forward : navigationInTransition.Backward;
                }
                if (newTransitionElement != null)
                {
                    newElement.UpdateLayout();
                    newTransition = newTransitionElement.GetTransition(newElement);
                    _newContentPresenter.CacheMode        = new BitmapCache();
                    _newContentPresenter.IsHitTestVisible = false;
                }
            }
            _newContentPresenter.Opacity    = 0;
            _newContentPresenter.Visibility = Visibility.Visible;
            _newContentPresenter.Content    = newElement;
            _oldContentPresenter.Opacity    = 1;
            _oldContentPresenter.Visibility = Visibility.Visible;
            _oldContentPresenter.Content    = oldElement;
            if (oldTransition != null)
            {
                if (oldTransition.GetCurrentState() != ClockState.Stopped)
                {
                    oldTransition.Stop();
                }
                oldTransition.Completed += delegate
                {
                    oldTransition.Stop();
                    _oldContentPresenter.CacheMode        = null;
                    _oldContentPresenter.IsHitTestVisible = true;
                    if (navigationOutTransition != null)
                    {
                        navigationOutTransition.OnEndTransition();
                    }
                    TransitionNewElement(newTransition, navigationInTransition);
                };
                Dispatcher.BeginInvoke(delegate
                {
                    Dispatcher.BeginInvoke(delegate
                    {
                        if (navigationOutTransition != null)
                        {
                            navigationOutTransition.OnBeginTransition();
                        }
                        oldTransition.Begin();
                    });
                });
            }
            else
            {
                TransitionNewElement(newTransition, navigationInTransition);
            }
        }
Example #4
0
 /// <summary>
 /// This checks to make sure that, if the transition not be in the clock
 /// state of Stopped, that is will be stopped.
 /// </summary>
 /// <param name="transition">The transition instance.</param>
 private static void EnsureStoppedTransition(ITransition transition)
 {
     if (transition != null && transition.GetCurrentState() != ClockState.Stopped)
     {
         transition.Stop();
     }
 }
 /// <summary>
 /// Transitions the new <see cref="T:System.Windows.UIElement"/>.
 /// </summary>
 /// <param name="newTransition">The <see cref="T:Microsoft.Phone.Controls.ITransition"/> for the new <see cref="T:System.Windows.UIElement"/>.</param>
 /// <param name="navigationInTransition">The <see cref="T:Microsoft.Phone.Controls.NavigationInTransition"/>  for the new <see cref="T:System.Windows.UIElement"/>.</param>
 private void TransitionNewElement(ITransition newTransition, NavigationInTransition navigationInTransition)
 {
     _oldContentPresenter.Visibility = Visibility.Collapsed;
     _oldContentPresenter.Content = null;
     if (newTransition == null)
     {
         _newContentPresenter.IsHitTestVisible = true;
         _newContentPresenter.Opacity = 1;
         return;
     }
     if (newTransition.GetCurrentState() != ClockState.Stopped)
     {
         newTransition.Stop();
     }
     newTransition.Completed += delegate
     {
         newTransition.Stop();
         _newContentPresenter.CacheMode = null;
         _newContentPresenter.IsHitTestVisible = true;
         if (navigationInTransition != null)
         {
             navigationInTransition.OnEndTransition();
         }
     };
     Dispatcher.BeginInvoke(delegate
     {
         if (navigationInTransition != null)
         {
             navigationInTransition.OnBeginTransition();
         }
         _newContentPresenter.Opacity = 1;
         newTransition.Begin();
     });
 }
 /// <summary>
 /// Transitions the new <see cref="T:System.Windows.UIElement"/>.
 /// </summary>
 /// <param name="oldContentPresenter">The old <see cref="T:System.Windows.Controls.ContentPresenter"/>.</param>
 /// <param name="newContentPresenter">The new <see cref="T:System.Windows.Controls.ContentPresenter"/>.</param>
 /// <param name="transition">The <see cref="T:Microsoft.Phone.Controls.ITransition"/>.</param>
 private static void TransitionNewElement(ContentPresenter oldContentPresenter, ContentPresenter newContentPresenter, ITransition transition)
 {
     oldContentPresenter.Visibility = Visibility.Collapsed;
     oldContentPresenter.Content = null;
     if (transition == null)
     {
         newContentPresenter.Opacity = 1;
     }
     else
     {
         if (transition.GetCurrentState() != ClockState.Stopped)
         {
             transition.Stop();
         }
         transition.Completed += delegate
         {
             transition.Stop();
         };
         newContentPresenter.Opacity = 1;
         transition.Begin();
     }
 }