Beispiel #1
0
        public void Render(DrawingContext drawingContext, DependencyObject o)
        {
            Visual visual = o as Visual;
            UIElement uiElement = o as UIElement;
            int popCount = 0;

            if (uiElement != null)
            {
                TranslateTransform translate = new TranslateTransform(uiElement.VisualOffset);
                drawingContext.PushTransform(translate);
                ++popCount;

                if (uiElement.Opacity != 1)
                {
                    drawingContext.PushOpacity(uiElement.Opacity);
                    ++popCount;
                }

                uiElement.OnRender(drawingContext);
            }

            if (visual != null)
            {
                for (int i = 0; i < visual.VisualChildrenCount; ++i)
                {
                    this.Render(drawingContext, visual.GetVisualChild(i));
                }
            }

            for (int i = 0; i < popCount; ++i)
            {
                drawingContext.Pop();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Starts the animation.
        /// </summary>
        /// <param name="from">
        /// The control that is being transitioned away from. May be null.
        /// </param>
        /// <param name="to">
        /// The control that is being transitioned to. May be null.
        /// </param>
        /// <param name="forward">
        /// If true, the new page is slid in from the right, or if false from the left.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that tracks the progress of the animation.
        /// </returns>
        public async Task Start(IVisual from, IVisual to, bool forward)
        {
            var tasks = new List<Task>();
            var parent = GetVisualParent(from, to);
            var distance = parent.Bounds.Width;

            if (from != null)
            {
                var transform = new TranslateTransform();
                from.RenderTransform = transform;
                tasks.Add(Animate.Property(
                    transform,
                    TranslateTransform.XProperty,
                    0.0,
                    forward ? -distance : distance,
                    LinearEasing.For<double>(),
                    Duration).ToTask());
            }

            if (to != null)
            {
                var transform = new TranslateTransform();
                to.RenderTransform = transform;
                to.IsVisible = true;
                tasks.Add(Animate.Property(
                    transform,
                    TranslateTransform.XProperty,
                    forward ? distance : -distance,
                    0.0,
                    LinearEasing.For<double>(),
                    Duration).ToTask());
            }

            await Task.WhenAll(tasks.ToArray());

            if (from != null)
            {
                from.IsVisible = false;
            }
        }