Esempio n. 1
0
        public VisualTreeItem FindNode(object target)
        {
            // it might be faster to have a map for the lookup
            // check into this at some point
            if (this.Target == target)
            {
                if (DXMethods.IsChrome(Target) && target is IInputElement)
                {
                    var root = DXMethods.GetRoot(Target);
                    if (root != null)
                    {
                        var child = RenderTreeHelper.HitTest(root, System.Windows.Input.Mouse.GetPosition((IInputElement)target));
                        var node  = FindNode(child);
                        if (node != null)
                        {
                            return(node);
                        }
                    }
                }
                return(this);
            }

            foreach (VisualTreeItem child in this.Children)
            {
                VisualTreeItem node = child.FindNode(target);
                if (node != null)
                {
                    return(node);
                }
            }
            return(null);
        }
Esempio n. 2
0
        static VisualTreeItem FindNode(VisualTreeItem currentVisualTreeItem, object target)
        {
            // it might be faster to have a map for the lookup
            // check into this at some point
            Queue <VisualTreeItem> items = new Queue <VisualTreeItem>();

            items.Enqueue(currentVisualTreeItem);
            while (items.Count > 0)
            {
                currentVisualTreeItem = items.Dequeue();
                if (currentVisualTreeItem.Target == target)
                {
                    var chrome = currentVisualTreeItem.Target.Wrap <IChrome>();
                    if (chrome != null && target is IInputElement)
                    {
                        var root = chrome.Root;
                        if (root != null)
                        {
                            var child = RenderTreeHelper.HitTest(root, Mouse.GetPosition((IInputElement)target));
                            var node  = currentVisualTreeItem.FindNode(child);
                            if (node != null)
                            {
                                return(node);
                            }
                        }
                    }
                    return(currentVisualTreeItem);
                }

                foreach (var child in currentVisualTreeItem.Children)
                {
                    items.Enqueue(child);
                }
            }
            return(null);
        }