public Point GetPosition(object?relativeTo)
            {
                CGPoint windowLocation = new CGPoint(0.0, 0.0);

                if (_macOSDraggingInfo != null && _window.ContentView is { } contentView)
                {
                    windowLocation = contentView.ConvertPointFromView(_macOSDraggingInfo.DraggingLocation, null);
                }
                var rawPosition = new Point(windowLocation.X, windowLocation.Y);

                if (relativeTo is null)
                {
                    return(rawPosition);
                }

                if (relativeTo is UIElement elt)
                {
                    var eltToRoot = UIElement.GetTransform(elt, null);
                    var rootToElt = eltToRoot.Inverse();

                    return(rootToElt.Transform(rawPosition));
                }

                throw new InvalidOperationException("The relative to must be a UIElement.");
            }
Example #2
0
        public ViewportInfo GetRelativeTo(IFrameworkElement_EffectiveViewport element)
        {
            Rect effective = Effective, clip = Clip;

            if (element is UIElement uiElement && Reference is UIElement usuallyTheParentOfElement)
            {
                var parentToElement = UIElement.GetTransform(uiElement, usuallyTheParentOfElement).Inverse();

                if (Effective.IsValid)
                {
                    effective = parentToElement.Transform(Effective);
                }

                if (Clip.IsValid)
                {
                    clip = parentToElement.Transform(Clip);
                }
            }

            // If the Reference or the element is not a UIElement (native), we don't have any RenderTransform,
            // and we assume that the 'element' is stretched in it's parent usually true except for ListView,
            // but we won't even try to support that case.

            return(new ViewportInfo(element, effective, clip));
        }
Example #3
0
            /// <inheritdoc />
            public Point GetPosition(object?relativeTo)
            {
                var rawWpfPosition = _wpfArgs.GetPosition(WpfHost.Current);
                var rawPosition    = new Point(rawWpfPosition.X, rawWpfPosition.Y);

                if (relativeTo is null)
                {
                    return(rawPosition);
                }

                if (relativeTo is UIElement elt)
                {
                    var eltToRoot = UIElement.GetTransform(elt, null);
                    Matrix3x2.Invert(eltToRoot, out var rootToElt);

                    return(rootToElt.Transform(rawPosition));
                }

                throw new InvalidOperationException("The relative to must be a UIElement.");
            }