示例#1
0
        internal static IEnumerable <T> GetElementsInHostCoordinates <T>(this UIElement subtree, Point position)  where T : UIElement
        {
            if (subtree == null)
            {
                return(Enumerable.Empty <T>());
            }

            var       elements = new List <T>(50);
            UIElement root     = ApplicationHelper.GetRootVisual(subtree);

            VisualTreeHelper.HitTest(subtree,
                                     null,
                                     r =>
            {
                UIElement e       = r.VisualHit as UIElement;
                var localElements = new List <UIElement>(50);
                while (e != null)
                {
                    if (e.Visibility == Visibility.Visible)
                    {
                        localElements.Add(e);
                    }
                    else
                    {
                        localElements.Clear();
                    }

                    e = VisualTreeHelper.GetParent(e) as UIElement;
                }
                elements.AddRange(localElements.OfType <T>());
                return(HitTestResultBehavior.Continue);
            },
                                     new PointHitTestParameters(position));

            return(elements);
        }
示例#2
0
 internal static IEnumerable <T> GetElementsInScreenCoordinates <T>(this FrameworkElement relativeTo, Point mousePosition) where T : UIElement
 {
     return(GetElementsInScreenCoordinates <T>(mousePosition, ApplicationHelper.GetRootVisual(relativeTo)));
 }