Exemplo n.º 1
0
        private void Batch_Completed(object sender, CompositionBatchCompletedEventArgs args)
        {
            // 1. Remove event handler from storyboard
            CompositionScopedBatch target = sender as CompositionScopedBatch;

            if (target != null)
            {
                target.Completed -= Batch_Completed;
                target.Dispose();

                _currentGroup?.Dispose();

                // 1.1 If this is the most recent storyboard, allow us to interact with content
                if (target == _currentBatch)
                {
                    RestoreContentPresenterInteractivity(_newPresenter);
                    _newPresenter.IsHitTestVisible = true;
                }
            }
            else
            {
                // if no target, we've manually called this. Make it work.
                _newPresenter.IsHitTestVisible = true;
                RestoreContentPresenterInteractivity(_newPresenter);
            }

            _currentBatch = null;
            _currentGroup = null;

            // Remove the "old" content (i.e. the thing we've animated out) from the VisualTree
            ContentPresenter presenter;

            lock (_presenters)
                presenter = _presenters.Dequeue();

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

            presenter = null;
        }
Exemplo n.º 2
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();
                    });
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the default backwards composition animation
        /// </summary>
        /// <param name="outElement"></param>
        /// <param name="inElement"></param>
        /// <returns></returns>
        CompositionStoryboard CreateCompositionExpoZoomBackward(FrameworkElement outElement, FrameworkElement inElement)
        {
            Compositor compositor = ElementCompositionPreview.GetElementVisual(outElement).Compositor;

            Visual outVisual = ElementCompositionPreview.GetElementVisual(outElement);
            Visual inVisual  = ElementCompositionPreview.GetElementVisual(inElement);

            CompositionAnimationGroup outgroup = compositor.CreateAnimationGroup();
            CompositionAnimationGroup ingroup  = compositor.CreateAnimationGroup();

            TimeSpan outDuration = TimeSpan.FromSeconds(0.3);
            TimeSpan inDuration  = TimeSpan.FromSeconds(0.4);

            CubicBezierEasingFunction ease = compositor.CreateCubicBezierEasingFunction(
                new Vector2(0.95f, 0.05f),
                new Vector2(0.79f, 0.04f));

            CubicBezierEasingFunction easeOut = compositor.CreateCubicBezierEasingFunction(
                new Vector2(0.19f, 1.0f),
                new Vector2(0.22f, 1.0f));


            // OUT ELEMENT
            {
                outVisual.CenterPoint = outVisual.Size.X > 0
                    ? new Vector3(outVisual.Size / 2f, 0f)
                    : new Vector3((float)this.ActualWidth / 2f, (float)this.ActualHeight / 2f, 0f);

                // SCALE OUT
                var sO = compositor.CreateVector3KeyFrameAnimation();
                sO.Duration = outDuration;
                sO.Target   = nameof(outVisual.Scale);
                sO.InsertKeyFrame(1, new Vector3(0.7f, 0.7f, 1.0f), ease);
                outgroup.Add(sO);

                // FADE OUT
                var op = compositor.CreateScalarKeyFrameAnimation();
                op.Duration = outDuration;
                op.Target   = nameof(outVisual.Opacity);
                op.InsertKeyFrame(1, 0f, ease);
                outgroup.Add(op);
            }

            // IN ELEMENT
            {
                inVisual.CenterPoint = inVisual.Size.X > 0
                     ? new Vector3(inVisual.Size / 2f, 0f)
                     : new Vector3((float)this.ActualWidth / 2f, (float)this.ActualHeight / 2f, 0f);


                // SCALE IN
                ingroup.Add(
                    inVisual.CreateVector3KeyFrameAnimation(nameof(Visual.Scale))
                    .AddScaleKeyFrame(0, 1.3f)
                    .AddScaleKeyFrame(1, 1f, easeOut)
                    .SetDuration(inDuration)
                    .SetDelayTime(outDuration)
                    .SetDelayBehavior(AnimationDelayBehavior.SetInitialValueBeforeDelay));

                // FADE IN
                inVisual.Opacity = 0f;
                var op = inVisual.Compositor.CreateScalarKeyFrameAnimation();
                op.DelayTime = outDuration;
                op.Duration  = inDuration;
                op.Target    = nameof(outVisual.Opacity);
                op.InsertKeyFrame(1, 0f, easeOut);
                op.InsertKeyFrame(1, 1f, easeOut);
                ingroup.Add(op);
            }

            CompositionStoryboard group = new CompositionStoryboard();

            group.Add(new CompositionTimeline(outVisual, outgroup, ease));
            group.Add(new CompositionTimeline(inVisual, ingroup, easeOut));
            return(group);
        }