public TreeItem FindStrategyNearItem(TreeItem treeItem)
        {
            if (treeItem == null)
            {
                return(null);
            }

            if (treeItem is LogicalTreeItem && SearchStrategy == SearchStrategy.VisualTree)
            {
                return(VisualTreeItem.FindVisualTreeItem(treeItem.Instance));
            }

            if (treeItem is VisualTreeItem && SearchStrategy == SearchStrategy.LogicalTree)
            {
                var logicalItem = LogicalTreeItem.FindLogicalTreeItem(treeItem.Instance);
                while (logicalItem == null)
                {
                    treeItem    = treeItem.Parent;
                    logicalItem = LogicalTreeItem.FindLogicalTreeItem(treeItem.Instance);
                }
                treeItem = logicalItem;
            }

            return(treeItem);
        }
Exemple #2
0
        private FrameworkElement FindLogicalElement(FrameworkElement element)
        {
            _selectedTreeItem = LogicalTreeItem.FindLogicalTreeItem(element);

            while (_selectedTreeItem == null && element != null && element.TemplatedParent != null)
            {
                element           = element.TemplatedParent as FrameworkElement;
                _selectedTreeItem = LogicalTreeItem.FindLogicalTreeItem(element);
            }

            while (_selectedTreeItem == null && element != null)
            {
                element           = VisualTreeHelper.GetParent(element) as FrameworkElement;
                _selectedTreeItem = LogicalTreeItem.FindLogicalTreeItem(element);
            }
            return(element);
        }