Example #1
0
        internal override Point GetPosition(IInputElement relativeTo)
        {
            VerifyAccess();

            // Validate that relativeTo is either a UIElement or a ContentElement
            if (relativeTo != null && !InputElement.IsValid(relativeTo))
            {
                throw new InvalidOperationException();
            }

            PresentationSource relativePresentationSource = null;

            if (relativeTo != null)
            {
                DependencyObject dependencyObject = relativeTo as DependencyObject;
                DependencyObject containingVisual = InputElement.GetContainingVisual(dependencyObject);
                if (containingVisual != null)
                {
                    relativePresentationSource = PresentationSource.CriticalFromVisual(containingVisual);
                }
            }
            else
            {
                if (_inputSource != null)
                {
                    relativePresentationSource = _inputSource.Value;
                }
            }

            // Verify that we have a valid PresentationSource with a valid RootVisual
            // - if we don't we won't be able to invoke ClientToRoot or TranslatePoint and
            //   we will just return 0,0
            if (relativePresentationSource == null || relativePresentationSource.RootVisual == null)
            {
                return(new Point(0, 0));
            }

            Point curPoint = new Point(_pointerData.Info.ptPixelLocationRaw.X, _pointerData.Info.ptPixelLocationRaw.Y);

            Point ptClient   = PointUtil.ScreenToClient(curPoint, relativePresentationSource);
            Point ptRoot     = PointUtil.ClientToRoot(ptClient, relativePresentationSource);
            Point ptRelative = InputElement.TranslatePoint(ptRoot, relativePresentationSource.RootVisual, (DependencyObject)relativeTo);

            return(ptRelative);
        }
Example #2
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// The point of drop operation that based on relativeTo.
        /// </summary>
        public Point GetPosition(IInputElement relativeTo)
        {
            Point dropPoint;

            if (relativeTo == null)
            {
                throw new ArgumentNullException("relativeTo");
            }

            dropPoint = new Point(0, 0);

            if (_target != null)
            {
                // Translate the drop point from the drop target to the relative element.
                dropPoint = InputElement.TranslatePoint(_dropPoint, _target, (DependencyObject)relativeTo);
            }

            return(dropPoint);
        }