示例#1
0
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            UIElement oldElement = oldContent as UIElement;
            UIElement newElement = newContent as UIElement;

            // Try to force ClientArea to be realized
            //this.ApplyTemplate();

            // Require the appropriate template parts plus a new element to
            // transition to.
            if (_clientArea == null)
            {
                return;
            }

            _oldPresenter = _newPresenter;
            _newPresenter = GetNewPresenter();

            _clientArea.Children.Insert(0, _newPresenter);

            SetOpacity(_newPresenter, 0);
            _newPresenter.Visibility = Visibility.Visible;
            _newPresenter.Content    = newElement;

            if (_oldPresenter != null)
            {
                _oldPresenter.GetVisual();
                lock (_presenters)
                    _presenters.Enqueue(_oldPresenter);
                SetOpacity(_oldPresenter, 1);
                _oldPresenter.Visibility       = Visibility.Visible;
                _oldPresenter.IsHitTestVisible = false;

                if (oldElement != null)
                {
                    _oldPresenter.Content = oldElement;
                }
            }

            // If we're not playing transitions, get in and out in a flash.
            if (SkipTransition)
            {
                SkipTransition = false;

                {
                    Sb_Completed(null, null);

                    if (_oldPresenter != null)
                    {
                        _clientArea.Children.Remove(_oldPresenter);
                        _oldPresenter.Content = null;
                        _oldPresenter         = null;
                    }

                    SetOpacity(_newPresenter, 1);
                }

                return;
            }

            if (oldElement == null)
            {
                SetOpacity(_newPresenter, 1);
            }
            else
            {
                if (AnimationEngine == NavigationAnimationEngine.Composition)
                {
                    SetOpacity(_newPresenter, 1);
                    //  Create a composition scoped batch. This will track when the transition completes
                    Compositor             comp  = _oldPresenter.GetVisual().Compositor;
                    CompositionScopedBatch batch = _currentBatch = comp.CreateScopedBatch(CompositionBatchTypes.Animation);
                    batch.Completed += Batch_Completed;

                    // Create a start the transition
                    CompositionStoryboard group = _currentGroup = GenerateCompositionTransition(_isForwardNavigation ? NavigationMode.New : NavigationMode.Back, _oldPresenter, _newPresenter);
                    group.Start();

                    // Seal the batch
                    batch.End();
                }
                else
                {
                    Storyboard sb = _currentTransition = GenerateStoryboardTransition(_isForwardNavigation ? NavigationMode.New : NavigationMode.Back, _oldPresenter, _newPresenter);
                    sb.Completed += Sb_Completed;

                    var a = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                    {
                        sb.Begin();
                    });
                }
            }
        }