/// <summary> /// Update the rectangular bound of the element /// This method is called from the application context. /// </summary> internal void UpdateRect() { // The RenderSize is only valid if IsArrangeValid is true. if (_element.IsArrangeValid && _element.IsEnabled && _element.IsVisible && _element.IsHitTestVisible) { _rc = new Rect(new Point(), _element.RenderSize);// _element.GetContentBoundingBox(); Visual root = VisualTreeHelper.GetContainingVisual2D(InputElement.GetRootVisual(_element)); try { _viewToElement = root.TransformToDescendant(_element); } catch (System.InvalidOperationException) { // This gets hit if the transform is not invertable. In that case // we will just not allow this plugin to be hit. _rc = new Rect(); // empty rect so we don't hittest it. _viewToElement = Transform.Identity; } } else { _rc = new Rect(); // empty rect so we don't hittest it. } if (_viewToElement == null) { _viewToElement = Transform.Identity; } }
/// <param name="o">The dependency object to find the source for</param> /// <param name="enable2DTo3DTransition"> /// Determines whether when walking the tree to enable transitioning from a 2D child /// to a 3D parent or to stop once a 3D parent is encountered. /// </param> private static PresentationSource FindSource(DependencyObject o, bool enable2DTo3DTransition) { PresentationSource source = null; // For "Visual" nodes GetRootVisual() climbs to the top of the // visual tree (parent==null) // For "ContentElements" it climbs the logical parent until it // reaches a visual then climbs to the top of the visual tree. DependencyObject v = InputElement.GetRootVisual(o, enable2DTo3DTransition); if (v != null) { source = CriticalGetPresentationSourceFromElement(v, RootSourceProperty); } return(source); }