Ejemplo n.º 1
0
        public static IEnumerable <UIElement> ScreenHitTest(Point screenPoint)
        {
#if SILVERLIGHT
            var uielements = new List <UIElement>();

            foreach (var visualRoot in PresentationTreeUtils.EnumerateVisualRoots().OfType <FrameworkElement>())
            {
                uielements.AddRange(VisualTreeHelper.FindElementsInHostCoordinates(screenPoint, visualRoot));
            }

            return(uielements);
#else
            var uielements = new List <UIElement>();

            foreach (var visualRoot in PresentationTreeUtils.EnumerateVisualRoots().OfType <FrameworkElement>().Where(fre => fre.Dispatcher.CheckAccess()))
            {
                VisualTreeHelper.HitTest(visualRoot, r =>
                {
                    var uie = r as UIElement;

                    if (uie != null)
                    {
                        uielements.Add(uie);
                    }

                    return(HitTestFilterBehavior.Continue);
                }, result => HitTestResultBehavior.Continue, new PointHitTestParameters(visualRoot.PointFromScreen(screenPoint)));
            }

            return(uielements.AsEnumerable().Reverse());
#endif
        }
Ejemplo n.º 2
0
        public static IEnumerable <UIElement> ScreenHitTest(Rect screenRect)
        {
#if SILVERLIGHT
            return(VisualTreeHelper.FindElementsInHostCoordinates(screenRect, Application.Current.RootVisual).ToList());
#else
            var uielements = new List <UIElement>();
            foreach (var visualRoot in PresentationTreeUtils.EnumerateVisualRoots().OfType <FrameworkElement>().Where(fre => fre.Dispatcher.CheckAccess()))
            {
                if (visualRoot.Dispatcher.CheckAccess() == false)
                {
                    continue;
                }

                VisualTreeHelper.HitTest(visualRoot, r =>
                {
                    var uie = r as UIElement;
                    if (uie != null)
                    {
                        uielements.Add(uie);
                    }
                    return(HitTestFilterBehavior.Continue);
                }, result => HitTestResultBehavior.Continue, new GeometryHitTestParameters(new RectangleGeometry(visualRoot.TransformRectToClient(screenRect))));
            }

            return(uielements.AsEnumerable().Reverse());
#endif
        }
Ejemplo n.º 3
0
        public override DependencyObject GetAncestor(DependencyObject dependencyObject)
        {
            if (dependencyObject == null)
            {
                return(null);
            }

            if (_disconnectedTree)
            {
                var disconnectedParent = PresentationTreeUtils.GetDisconnectedParent(dependencyObject);
                if (disconnectedParent != null)
                {
                    return(disconnectedParent);
                }
            }

            return(_firstStrategy.GetAncestor(dependencyObject) ?? _secondStrategy.GetAncestor(dependencyObject));
        }
Ejemplo n.º 4
0
 public override DependencyObject GetAncestor(DependencyObject dependencyObject)
 {
     return(PresentationTreeUtils.GetLogicalParent(dependencyObject));
 }