TransformToVisual() public method

public TransformToVisual ( [ visual ) : GeneralTransform
visual [
return Windows.UI.Xaml.Media.GeneralTransform
Esempio n. 1
0
        public static double DistanceFromTop(this ScrollViewer scrollViewer, UIElement element)
        {
            var transform = element.TransformToVisual(scrollViewer);
            var position = transform.TransformPoint(new Point(0, 0));

            return position.Y;
        }
Esempio n. 2
0
        /// <summary>
        /// Set up Continuity by hooking continuing Visuals to root Frame and getting global co-ordinates so that Visual seems to remain on the same location even though pages change and local coordinate space changes as well. 
        /// </summary>
        /// <param name="containerVisual">Container Visual which contains visual that needs to continue between pages</param>
        /// <param name="hostElement">UIElement which the Visual is hosted in</param>
        /// <param name="newContainerVisual">new ContainerVisual after re-parent of sprite Visual to root.</param>
        public static void SetupContinuity(ContainerVisual containerVisual,UIElement HostElement, out ContainerVisual newContainerVisual)
        {
            if (null == containerVisual || null == HostElement)
            {
                newContainerVisual = null;
                return;
            }
            Frame rootFrame = Window.Current.Content as Frame;
            Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootFrame);
            Compositor compositor = rootVisual.Compositor;
            //remove element from current tree 
            var visualChild = containerVisual.Children.FirstOrDefault();
            containerVisual.Children.Remove(visualChild);

            //create temp container to add the visual to the root 
            ContainerVisual tempContainer = compositor.CreateContainerVisual();
            tempContainer.Children.InsertAtTop(visualChild);
            //Get location of visual as compared to root frame. 
            var coordinate = HostElement.TransformToVisual(rootFrame);
            var position = coordinate.TransformPoint(new Point(0, 0));
            //set the location of container visual to same visual location but now root as the parent.
            tempContainer.Offset = new System.Numerics.Vector3((float)position.X, (float)position.Y, 0);
            visualChild.Offset = new System.Numerics.Vector3(0, 0, 0);

            //add container with sprite to the window of app
            ElementCompositionPreview.SetElementChildVisual(rootFrame, tempContainer);
            containerVisual = null;
            newContainerVisual = tempContainer;
        }
Esempio n. 3
0
        public static void ScrollToElement(this ScrollViewer scrollViewer, UIElement element,
    bool isVerticalScrolling = true, bool smoothScrolling = true, float? zoomFactor = null)
        {
            var transform = element.TransformToVisual((UIElement)scrollViewer.Content);
            var position = transform.TransformPoint(new Point(0, 0));

            if (isVerticalScrolling)
            {
                scrollViewer.ChangeView(null, position.Y, zoomFactor, !smoothScrolling);
            }
            else
            {
                scrollViewer.ChangeView(position.X, null, zoomFactor, !smoothScrolling);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 显示菜单
        /// </summary>
        public void ShowAt(UIElement element, Point point)
        {
            if (element == null) return;

            var p = element.TransformToVisual(Window.Current.Content).TransformPoint(new Point(0, 0));
            _popup.IsLightDismissEnabled = _isLightDismissEnabled;
            _popup.HorizontalOffset = p.X + point.X;
            _popup.VerticalOffset = p.Y + point.Y;
            _popup.IsOpen = true;
        }
        private Point CalcOffsets(UIElement elem)
        {
            var transform = elem.TransformToVisual(this);
            Point point = transform.TransformPoint(new Point(0, 0));

            return point;
        }
 Point TransformToCanvas(UIElement elem, Point pt)
 {
     GeneralTransform gt = elem.TransformToVisual(_physicsCanvas);
     return gt.TransformPoint(pt);
 }
Esempio n. 7
0
        /// <summary>
        /// Calculates the new Value of this control using a location and relative source.
        /// The location is translated to the control, and then used to set the value.
        /// </summary>
        /// <param name="location">A point.</param>
        /// <param name="locationRelativeSource">The UIElement that the point originated from.</param>
        private void PerformValueCalculation(Point location, UIElement locationRelativeSource)
        {
            GeneralTransform gt = locationRelativeSource.TransformToVisual(this);
            location = gt.TransformPoint(location);

            int numberOfPositions = _filledItemCollection.Count;

            if (AllowHalfItemIncrement)
            {
                numberOfPositions *= 2;
            }

            double newValue;
            if (Orientation == Orientation.Horizontal)
            {
                newValue = Math.Ceiling(location.X / ActualWidth * numberOfPositions);
            }
            else
            {
                newValue = Math.Ceiling(location.Y / ActualHeight * numberOfPositions);
            }

            if (!AllowSelectingZero && newValue <= 0)
            {
                newValue = 1;
            }

            Value = newValue;
        }
Esempio n. 8
0
        private void ShowFontPopup(UIElement targetElement)
        {
            _popUp.Child = _fontSizePopupMenu;
            var transform = targetElement.TransformToVisual(null);
            var point = transform.TransformPoint(new Point(0, 0));
            _popUp.HorizontalOffset = point.X - 40;// this.ScreenWidth - 180;
            _popUp.VerticalOffset = point.Y - 220;

            _popUp.IsOpen = true;
        }
        public void Start(UIElement newParent, CompositionImage targetImage, ScrollViewer scrollViewer, UIElement animationTarget)
        {
            Visual transitionVisual = ElementCompositionPreview.GetElementChildVisual(_parent);
            ElementCompositionPreview.SetElementChildVisual(_parent, null);


            //
            // We need to reparent the transition visual under the new parent.  This is important to ensure
            // it's propertly clipped, etc.
            //

            GeneralTransform coordinate = newParent.TransformToVisual(_parent);
            Point position = coordinate.TransformPoint(new Point(0, 0));

            Vector3 currentOffset = transitionVisual.Offset;
            currentOffset.X -= (float)position.X;
            currentOffset.Y -= (float)position.Y;
            transitionVisual.Offset = currentOffset;

            _parent = newParent;
            _targetImage = targetImage;

            // Move the transition visual to it's new parent
            ElementCompositionPreview.SetElementChildVisual(_parent, transitionVisual);

            // Hide the target Image now since the handoff visual is still transitioning
            targetImage.Opacity = 0f;

            // Load image if necessary
            _imageLoaded = targetImage.IsContentLoaded;
            if (!_imageLoaded)
            {
                targetImage.ImageOpened += CompositionImage_ImageOpened;
            }

            //
            // Create a scoped batch around the animations.  When the batch completes, we know the animations
            // have finished and we can cleanup the transition related objects.
            //

            Compositor compositor = transitionVisual.Compositor;
            _scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            //
            // Determine the offset between the parent and the target UIElement.  This will be used to calculate the
            // target position we are animating to.
            //

            coordinate = targetImage.TransformToVisual(_parent);
            position = coordinate.TransformPoint(new Point(0, 0));

            TimeSpan totalDuration = TimeSpan.FromMilliseconds(1000);
            Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();

            if (scrollViewer != null)
            {
                CompositionPropertySet scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer);

                // Include the scroller offset as that is a factor
                position.X += scrollViewer.HorizontalOffset;
                position.Y += scrollViewer.VerticalOffset;


                //
                // Since the target position is relative to the target UIElement which can move, we need to construct
                // an expression to bind the target's position to the end position of our animation.
                //

                string expression = "Vector3(scrollingProperties.Translation.X, scrollingProperties.Translation.Y, 0) + itemOffset";
                offsetAnimation.InsertExpressionKeyFrame(1f, expression);
                offsetAnimation.SetReferenceParameter("scrollingProperties", scrollProperties);
                offsetAnimation.SetVector3Parameter("itemOffset", new Vector3((float)position.X, (float)position.Y, 0));
                offsetAnimation.Duration = totalDuration;
            }
            else
            {
                offsetAnimation.InsertKeyFrame(1, new Vector3((float)position.X, (float)position.Y, 0));
                offsetAnimation.Duration = totalDuration;
            }

            // Create size animation to change size of the visual
            Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation();
            sizeAnimation.InsertKeyFrame(1f, new Vector2((float)targetImage.ActualWidth, (float)targetImage.ActualHeight));
            sizeAnimation.Duration = totalDuration;

            // Create the fade in animation for the other page content
            if (animationTarget != null)
            {
                Visual fadeVisual = ElementCompositionPreview.GetElementVisual(animationTarget);
                ScalarKeyFrameAnimation fadeIn = compositor.CreateScalarKeyFrameAnimation();
                fadeIn.InsertKeyFrame(0f, 0.0f);
                fadeIn.InsertKeyFrame(1f, 1.0f);
                fadeIn.Duration = totalDuration;
                fadeVisual.StartAnimation("Opacity", fadeIn);
            }

            //Start Animations 
            _sprite.StartAnimation("Size", sizeAnimation);
            _sprite.StartAnimation("Offset", offsetAnimation);

            //Scoped batch completed event
            _scopeBatch.Completed += ScopeBatch_Completed;
            _scopeBatch.End();

            // Clear the flag
            _animationCompleted = false;
        }