示例#1
0
        internal DependencyObject GetUIParent(bool continuePastVisualTree)
        {
            DependencyObject e = null;

            // Try to find a UIElement parent in the visual ancestry.
            e = InputElement.GetContainingInputElement(_parent) as DependencyObject;

            // If there was no InputElement parent in the visual ancestry,
            // check along the logical branch.
            if (e == null && continuePastVisualTree)
            {
                DependencyObject doParent = GetUIParentCore();
                e = InputElement.GetContainingInputElement(doParent) as DependencyObject;
            }

            return(e);
        }
示例#2
0
        internal static DependencyObject GetUIParent(DependencyObject child, bool continuePastVisualTree)
        {
            DependencyObject parent   = null;
            DependencyObject myParent = null;

            // Try to find a UIElement parent in the visual ancestry.
            if (child is Visual)
            {
                myParent = ((Visual)child).InternalVisualParent;
            }
            else
            {
                myParent = ((Visual3D)child).InternalVisualParent;
            }

            parent = InputElement.GetContainingUIElement(myParent) as DependencyObject;

            // If there was no UIElement parent in the visual ancestry,
            // check along the logical branch.
            if (parent == null && continuePastVisualTree)
            {
                UIElement childAsUIElement = child as UIElement;
                if (childAsUIElement != null)
                {
                    parent = InputElement.GetContainingInputElement(childAsUIElement.GetUIParentCore()) as DependencyObject;
                }
                else
                {
                    UIElement3D childAsUIElement3D = child as UIElement3D;
                    if (childAsUIElement3D != null)
                    {
                        parent = InputElement.GetContainingInputElement(childAsUIElement3D.GetUIParentCore()) as DependencyObject;
                    }
                }
            }

            return(parent);
        }
示例#3
0
        internal IInputElement FindTarget(PresentationSource inputSource, Point position)
        {
            IInputElement stylusOver = null;

            switch (_captureMode)
            {
            case CaptureMode.None:
            {
                stylusOver = StylusDevice.GlobalHitTest(inputSource, position);

                // We understand UIElements and ContentElements.
                // If we are over something else (like a raw visual)
                // find the containing element.
                if (!InputElement.IsValid(stylusOver))
                {
                    stylusOver = InputElement.GetContainingInputElement(stylusOver as DependencyObject);
                }
            }
            break;

            case CaptureMode.Element:
                stylusOver = _stylusCapture;
                break;

            case CaptureMode.SubTree:
            {
                IInputElement stylusCapture = InputElement.GetContainingInputElement(_stylusCapture as DependencyObject);

                if (stylusCapture != null && inputSource != null)
                {
                    // We need to re-hit-test to get the "real" UIElement we are over.
                    // This allows us to have our capture-to-subtree span multiple windows.

                    // GlobalHitTest always returns an IInputElement, so we are sure to have one.
                    stylusOver = StylusDevice.GlobalHitTest(inputSource, position);
                }

                if (stylusOver != null && !InputElement.IsValid(stylusOver))
                {
                    stylusOver = InputElement.GetContainingInputElement(stylusOver as DependencyObject);
                }

                // Make sure that the element we hit is acutally underneath
                // our captured element.  Because we did a global hit test, we
                // could have hit an element in a completely different window.
                //
                // Note that we support the child being in a completely different window.
                // So we use the GetUIParent method instead of just looking at
                // visual/content parents.
                if (stylusOver != null)
                {
                    IInputElement  ieTest = stylusOver;
                    UIElement      eTest  = null;
                    ContentElement ceTest = null;

                    while (ieTest != null && ieTest != stylusCapture)
                    {
                        eTest = ieTest as UIElement;

                        if (eTest != null)
                        {
                            ieTest = InputElement.GetContainingInputElement(eTest.GetUIParent(true));
                        }
                        else
                        {
                            ceTest = ieTest as ContentElement;         // Should never fail.

                            ieTest = InputElement.GetContainingInputElement(ceTest.GetUIParent(true));
                        }
                    }

                    // If we missed the capture point, we didn't hit anything.
                    if (ieTest != stylusCapture)
                    {
                        stylusOver = _stylusCapture;
                    }
                }
                else
                {
                    // We didn't hit anything.  Consider the stylus over the capture point.
                    stylusOver = _stylusCapture;
                }
            }
            break;
            }

            return(stylusOver);
        }