Пример #1
0
        private IEnumerable <UIElement> ElementAndAncestors(IInputElement mouseOver)
        {
            UIElement mo = (UIElement)mouseOver;

            if (mo != null)
            {
                yield return(mo);

                foreach (UIElement e in VisualTreeHelper.GetAncestors(mo).OfType <UIElement>())
                {
                    yield return(e);
                }
            }
        }
Пример #2
0
        public Point GetPosition(IInputElement relativeTo)
        {
            Point  p = this.GetClientPosition();
            Visual v = (Visual)relativeTo;

            if (v != null)
            {
                p -= v.VisualOffset;

                foreach (Visual ancestor in VisualTreeHelper.GetAncestors(v).OfType <Visual>())
                {
                    p -= ancestor.VisualOffset;
                }
            }

            return(p);
        }