public static Rect GetElementRect(Windows.UI.Xaml.FrameworkElement element)
        {
            Windows.UI.Xaml.Media.GeneralTransform transform = element.TransformToVisual(null);
            Point point = transform.TransformPoint(new Point());

            return(new Rect(point, new Size(element.ActualWidth, element.ActualHeight)));
        }
Пример #2
0
        public static bool IsItemVisible(this FrameworkElement container, FrameworkElement element)
        {
            var elementBounds = element.TransformToVisual(container).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight));
            var containerBounds = new Rect(0, 0, container.ActualWidth, container.ActualHeight);

            return (elementBounds.Top < containerBounds.Bottom && elementBounds.Bottom > containerBounds.Top);
        }
Пример #3
0
        private Point GetPosition(FrameworkElement sender)
        {
            GeneralTransform transform = sender.TransformToVisual(null);
            Point location = transform.TransformPoint(new Point());
            location.Y = location.Y + sender.ActualHeight;

            return location;
        }
Пример #4
0
 private Rect GetElementBounds(FrameworkElement element, FrameworkElement parent)
 {
     if (element == null || parent == null)
     {
         return Rect.Empty;
     }
     if (element.Visibility != Visibility.Visible)
     {
         return Rect.Empty;
     }
     return element.TransformToVisual(parent).TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight));
 }
Пример #5
0
        //get the bounding rect of an element relative to 0,0
        private static Rect GetElementRect(FrameworkElement element)
        {
            //get the element point to open the window at the correct point
            GeneralTransform transform = element.TransformToVisual(null);
            Point point = transform.TransformPoint(new Point());

            return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
        }
Пример #6
0
 private Rect GetElementRect(FrameworkElement frameworkElement)
 {
     Windows.UI.Xaml.Media.GeneralTransform transform = frameworkElement.TransformToVisual(null);
     Point point = transform.TransformPoint(new Point());
     return new Rect(point, new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight));
 }
Пример #7
0
        internal void ScrollIntoView(FrameworkElement element)
        {
            var scrollHost = ScrollHost;
            if (scrollHost == null)
            {
                return;
            }
            GeneralTransform transform;
            try
            {
                transform = element.TransformToVisual(scrollHost);
            }
            catch (ArgumentException)
            {
                return;
            }
            var itemRect = new Rect(transform.TransformPoint(new Point()),
                transform.TransformPoint(new Point(element.ActualWidth, element.ActualHeight)));
            var verticalOffset = scrollHost.VerticalOffset;
            double verticalDelta = 0;
            var hostBottom = scrollHost.ViewportHeight;
            var itemBottom = itemRect.Bottom;
            if (hostBottom < itemBottom)
            {
                verticalDelta = itemBottom - hostBottom;
                verticalOffset += verticalDelta;
            }
            var itemTop = itemRect.Top;
            if (itemTop - verticalDelta < 0)
            {
                verticalOffset -= verticalDelta - itemTop;
            }

            var horizontalOffset = scrollHost.HorizontalOffset;
            double horizontalDelta = 0;
            var hostRight = scrollHost.ViewportWidth;
            var itemRight = itemRect.Right;
            if (hostRight < itemRight)
            {
                horizontalDelta = itemRight - hostRight;
                horizontalOffset += horizontalDelta;
            }
            var itemLeft = itemRect.Left;
            if (itemLeft - horizontalDelta < 0)
            {
                horizontalOffset -= horizontalDelta - itemLeft;
            }
            scrollHost.ChangeView(horizontalOffset, verticalOffset, null);
        }
Пример #8
0
        /// <summary>
        /// Start animations and re-parent to destination UI Elmenent to finish the operations
        /// </summary>
        /// <param name="destinationElement">Destination UIElement where Visual should show up after page has loaded</param>
        /// <param name="containerVisual">ContainerVisual that contains Visual which needs to show in UIElement</param>
        /// <param name="newContainerVisual">ContainerVisual after visual is parented to UIElement</param>
        public static void InitiateContinuity(FrameworkElement destinationElement, ContainerVisual containerVisual, out ContainerVisual newContainerVisual)
        {
            if (null == containerVisual || null == destinationElement)
            {
                newContainerVisual = null;
                return;
            }
            //Get the frame of Window
            Frame rootFrame = Window.Current.Content as Frame;
            Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootFrame);
            Compositor compositor = rootVisual.Compositor;
            //Create Temporary Container. this will be added to final UIElement 
            ContainerVisual _TempContainer = compositor.CreateContainerVisual();
            // Get Sprite Visual from incoming container
            var spriteHeroImage = containerVisual.Children.FirstOrDefault();

            //Create animation scoped batch to track animation completion and to complete re-parenting
            CompositionScopedBatch scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            //Get coordinates of UIElement in reference to root so that it can be used for animations final value
            var coordinate = destinationElement.TransformToVisual(rootFrame);
            var position = coordinate.TransformPoint(new Point(0, 0));
            
            //Create offset animation to make visual move on screen
            Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            offsetAnimation.InsertKeyFrame(1f, new System.Numerics.Vector3((float)position.X, (float)position.Y, 0));
            offsetAnimation.Duration = TimeSpan.FromMilliseconds(600);

            //Create size animation to change size of the visuals 
            Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation();
            sizeAnimation.InsertKeyFrame(1f, new System.Numerics.Vector2((float)destinationElement.ActualWidth, (float)destinationElement.ActualHeight));
            sizeAnimation.Duration = TimeSpan.FromMilliseconds(600);

            //Start Animations 
            spriteHeroImage.StartAnimation("size", sizeAnimation);
            containerVisual.StartAnimation("offset", offsetAnimation);
            //Scoped batch completed event. 
            scopeBatch.Completed += (o, e) =>
            {
                //Re-parent SpriteVisual to temp container and add temp container to UIElement as animations are finished.
                spriteHeroImage.Offset = new System.Numerics.Vector3(0, 0, 0);
                containerVisual.Children.Remove(spriteHeroImage);
                _TempContainer.Children.InsertAtTop(spriteHeroImage);
                ElementCompositionPreview.SetElementChildVisual(destinationElement, _TempContainer);
                containerVisual = null;

            };
            newContainerVisual = _TempContainer;

            scopeBatch.End();
        }
Пример #9
0
 private Windows.Foundation.Rect GetElementRect(FrameworkElement element)
 {
     Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);
     Windows.Foundation.Point point = buttonTransform.TransformPoint(new Windows.Foundation.Point());
     return new Windows.Foundation.Rect(point, new Windows.Foundation.Size(element.ActualWidth, element.ActualHeight));
 }
Пример #10
0
 private Rect GetElementRect(FrameworkElement element)
 {
     var elementTransform = element.TransformToVisual(null);
     var point = elementTransform.TransformPoint(new Point());
     return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
 }
Пример #11
0
 public static Rect GetContainerRectangle([NotNull] this FrameworkElement element)
 {
     return(element.TransformToVisual(Window.Current.Content).TransformBounds(LayoutInformation.GetLayoutSlot(element)));
 }
Пример #12
0
        private Point[] GetTransformedPoints(FrameworkElement element, bool isRTL, FrameworkElement relativeTo)
        {
            Point[] pointArray = new Point[4];
            if ((element != null) && (relativeTo != null))
            {
                GeneralTransform gt = relativeTo.TransformToVisual(_rootVisual);
                pointArray[0] = gt.TransformPoint(new Point(0.0, 0.0));
                pointArray[1] = gt.TransformPoint(new Point(element.ActualWidth, 0.0));
                pointArray[2] = gt.TransformPoint(new Point(0.0, element.ActualHeight));
                pointArray[3] = gt.TransformPoint(new Point(element.ActualWidth, element.ActualHeight));

                FrameworkElement _el = _rootVisual as FrameworkElement;
                bool flag = (_el != null) ? (_el.FlowDirection == FlowDirection.RightToLeft) : false;
                if (isRTL != flag)
                {
                    // TODO: Handle RTL - GetTransformedPoints
                    //for (int i = 0; i < pointArray.Length; i++)
                    //{
                    //    pointArray[i].X = _windowBounds.Width - pointArray[i].X;
                    //}
                }
            }
            return pointArray;
        }
Пример #13
0
        internal void ScrollIntoView(FrameworkElement element)
        {
            // Get the ScrollHost
            ScrollViewer scrollHost = ScrollHost;

            if (scrollHost == null)
            {
                return;
            }

            // Get the position of the element relative to the ScrollHost
            GeneralTransform transform = null;

            try
            {
                transform = element.TransformToVisual(scrollHost);
            }
            catch (ArgumentException)
            {
                // Ignore failures when not in the visual tree
                return;
            }

            Rect itemRect = new Rect(
                transform.TransformPoint(new Point()),
                transform.TransformPoint(new Point(element.ActualWidth, element.ActualHeight)));

            // Scroll vertically
            double verticalOffset = scrollHost.VerticalOffset;
            double verticalDelta = 0;
            double hostBottom = scrollHost.ViewportHeight;
            double itemBottom = itemRect.Bottom;

            if (hostBottom < itemBottom)
            {
                verticalDelta = itemBottom - hostBottom;
                verticalOffset += verticalDelta;
            }

            double itemTop = itemRect.Top;

            if (itemTop - verticalDelta < 0)
            {
                verticalOffset -= verticalDelta - itemTop;
            }

#pragma warning disable 4014
            scrollHost.ScrollToVerticalOffsetWithAnimationAsync(verticalOffset);
#pragma warning restore 4014

            // Scroll horizontally
            double horizontalOffset = scrollHost.HorizontalOffset;
            double horizontalDelta = 0;
            double hostRight = scrollHost.ViewportWidth;
            double itemRight = itemRect.Right;

            if (hostRight < itemRight)
            {
                horizontalDelta = itemRight - hostRight;
                horizontalOffset += horizontalDelta;
            }

            double itemLeft = itemRect.Left;

            if (itemLeft - horizontalDelta < 0)
            {
                horizontalOffset -= horizontalDelta - itemLeft;
            }

#pragma warning disable 4014
            scrollHost.ScrollToHorizontalOffsetWithAnimationAsync(horizontalOffset);
#pragma warning restore 4014
        }
Пример #14
0
 public static Rect GetElementRect(FrameworkElement element)
 {
     GeneralTransform buttonTransform = element.TransformToVisual(null);
     Windows.Foundation.Point point = buttonTransform.TransformPoint(new Windows.Foundation.Point());
     return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
 }
Пример #15
0
 public static Rect GetElementRect(FrameworkElement element)
 {
     Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);
     Point point = buttonTransform.TransformPoint(new Point());
     return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
 }
Пример #16
0
 /// <summary>
 /// Determine whether an element is visible, assuming the container is visible.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="container"></param>
 /// <returns></returns>
 private Boolean IsUserVisible(FrameworkElement element, FrameworkElement container)
 {
     if (element == null)
         return false;
     Rect elementBounds = element.TransformToVisual(container)
         .TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight));
     Rect containerBounds = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);
     return (elementBounds.Top < containerBounds.Bottom && elementBounds.Bottom > containerBounds.Top)
         && (elementBounds.Left < containerBounds.Right && elementBounds.Right > containerBounds.Left);
 }
        /// <summary>
        /// Translates an element to another element's position
        /// </summary>
        /// <param name="element">Element to translate</param>
        /// <param name="target">Target element</param>
        /// <param name="durationInSeconds">Duration in seconds</param>
        /// <param name="OnComplete">[Optional] Action to perform on complete</param>
        /// <returns>Storyboard created</returns>
        public async static Task<Storyboard> BeginTranslationToElementAsync(this FrameworkElement element,
            FrameworkElement target, double durationInSeconds, Action OnComplete = null)
        {
            ValidateForNull(element);
            ValidateCompositeTransform(element);
            Point point = target.TransformToVisual(element).TransformPoint(new Point(0, 0));

            CompositeTransform ct = element.RenderTransform as CompositeTransform;
            return await TranslateToAsync(element, point.X + ct.TranslateX,
                point.Y + ct.TranslateY, durationInSeconds, OnComplete);


        }
Пример #18
0
 public static Rect GetElementRect(FrameworkElement element)
 {
     var buttonTransform = element.TransformToVisual(null);
     var point = buttonTransform.TransformPoint(new Point());
     return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
 }
Пример #19
0
 private Point GetPosition(FrameworkElement element)
 {
     return element.TransformToVisual(this.listBox).TransformPoint(new Point(0, 0));
 }
Пример #20
0
 /// <summary>
 /// Computes the delta between the centre of an element and its 
 /// container.
 /// </summary>
 /// <param name="element">The element to compare.</param>
 /// <param name="container">The element to compare against.</param>
 /// <returns>A point that represents the delta between the two centers.</returns>
 private static Point GetCenterToCenterDelta(FrameworkElement element, FrameworkElement container)
 {
     Point elementCenter = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
     Point containerCenter = new Point(container.ActualWidth / 2, container.ActualHeight / 2);
     Point transformedElementCenter = element.TransformToVisual(container).TransformPoint(elementCenter);
     return new Point(containerCenter.X - transformedElementCenter.X, containerCenter.Y - transformedElementCenter.Y);
 }
Пример #21
0
 private Rect GetElementRect(FrameworkElement element)
 {
   GeneralTransform buttonTransform = element.TransformToVisual(null);
   Point point = buttonTransform.TransformPoint(new Point());
   return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
 }
Пример #22
0
        /// <summary>
        // The Open With dialog should be displayed just under the element that triggered it.
        /// </summary>
        private Windows.Foundation.Point GetOpenWithPosition(FrameworkElement element)
        {
            Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);

            Point desiredLocation = buttonTransform.TransformPoint(new Point());
            desiredLocation.Y = desiredLocation.Y + element.ActualHeight;

            return desiredLocation;
        }
Пример #23
0
        private void BuildPopup(FrameworkElement source)
        {
            var windowBounds = Window.Current.Bounds;
            var rootVisual = Window.Current.Content;

            GeneralTransform gt = source.TransformToVisual(rootVisual);

            var absolutePosition = gt.TransformPoint(new Point(0, 0));

            var content = (FrameworkElement)_popup.Child;
            content.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            var contentWidth = double.IsNaN(content.Width) ? content.DesiredSize.Width : content.Width;
            var contentHeight = double.IsNaN(content.Height) ? content.DesiredSize.Height : content.Height;
            double vOffset = 0;
            double hOffset = 0;

            double vOffsetAnim = 0;
            double hOffsetAnim = 0;
            switch (PopupPlacement)
            {
                case Placement.Above:
                    vOffset = absolutePosition.Y - contentHeight - 10;
                    hOffset = (absolutePosition.X) + source.ActualWidth / 2 - contentWidth / 2;
                    vOffsetAnim = 20;
                    break;
                case Placement.Below:
                    vOffset = absolutePosition.Y + source.ActualHeight + 10;
                    hOffset = (absolutePosition.X) + source.ActualWidth / 2 - contentWidth / 2;
                    vOffsetAnim = -20;
                    break;
                case Placement.Default:
                case Placement.Left:
                    vOffset = absolutePosition.Y - contentHeight / 2 + source.ActualHeight / 2;
                    hOffset = (absolutePosition.X) - 10 - contentWidth;
                    hOffsetAnim = 20;
                    break;
                case Placement.Right:
                    vOffset = absolutePosition.Y - contentHeight / 2 + source.ActualHeight / 2;
                    hOffset = (absolutePosition.X) + 10 + source.ActualWidth;
                    hOffsetAnim = -20;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            //Limite position to windows bound
            vOffset = Math.Max(10, Math.Min(vOffset, windowBounds.Height - contentHeight - 10));
            hOffset = Math.Max(10, Math.Min(hOffset, windowBounds.Width - contentWidth - 10));

            _popup.VerticalOffset = vOffset;
            _popup.HorizontalOffset = hOffset;

            if (UseAnimation)
            {
                var transitions = new TransitionCollection();
                transitions.Add(new PopupThemeTransition()
                    {
                        FromHorizontalOffset = hOffsetAnim,
                        FromVerticalOffset = vOffsetAnim
                    });
                _popup.ChildTransitions = transitions;
            }
        }
        public static bool IsElementFullVisible(FrameworkElement element, FrameworkElement container)
        {
            if (element.Visibility == Visibility.Collapsed)
                return false;

            var elementSize = new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight);

            Rect bounds = element.TransformToVisual(container).TransformBounds(elementSize);

            var parentBounds = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);

            return parentBounds.Contains(new Point(bounds.Left, bounds.Top)) && parentBounds.Contains(new Point(bounds.Right, bounds.Bottom));
        }
Пример #25
0
        private static Rect GetPositionOfElement(FrameworkElement element)
        {
            if (element == null)
                return Rect.Empty;

            Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);
            var point = buttonTransform.TransformPoint(new Point());
            var rect = new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
            return rect;
        }