Пример #1
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            ProperTreeViewItem treeViewItem = new ProperTreeViewItem(_treeView);

            treeViewItem.Indent = this.Indent + 12;
            return(treeViewItem);
        }
Пример #2
0
 protected override DependencyObject GetContainerForItemOverride()
 {
     if (_pendingRoot != null)
     {
         _pendingRoot.Loaded -= OnRootLoaded;
         _pendingRoot         = null;
     }
     _pendingRoot         = new ProperTreeViewItem(new WeakReference(this));
     _pendingRoot.Loaded += OnRootLoaded;
     _maxDepth            = 0;
     _rootItem.Target     = null;
     return(_pendingRoot);
 }
Пример #3
0
		protected override DependencyObject GetContainerForItemOverride()
		{
			if (_pendingRoot != null)
			{
				_pendingRoot.Loaded -= OnRootLoaded;
				_pendingRoot = null;
			}
			_pendingRoot = new ProperTreeViewItem(new WeakReference(this));
			_pendingRoot.Loaded += OnRootLoaded;
			_maxDepth = 0;
			_rootItem.Target = null;
			return _pendingRoot;
		}
Пример #4
0
        private void OnRootLoaded()
        {
            // The following assumptions are made:
            // 1. The visual structure of each TreeViewItem is the same regardless of its location.
            // 2. The control template of a TreeViewItem contains ItemsPresenter.
            ProperTreeViewItem root = _pendingRoot;

            _pendingRoot = null;
            root.Loaded -= OnRootLoaded;

            ItemsPresenter itemsPresenter = null;

            VisualTreeHelper2.EnumerateTree(root, null,
                                            delegate(object visual, object misc)
            {
                itemsPresenter = visual as ItemsPresenter;
                if (itemsPresenter != null && itemsPresenter.TemplatedParent == root)
                {
                    return(HitTestResultBehavior.Stop);
                }
                else
                {
                    itemsPresenter = null;
                    return(HitTestResultBehavior.Continue);
                }
            },
                                            null);

            if (itemsPresenter != null)
            {
                int levelLayoutDepth = 2;
                DependencyObject tmp = itemsPresenter;
                while (tmp != root)
                {
                    ++levelLayoutDepth;
                    tmp = VisualTreeHelper.GetParent(tmp);
                }

                int rootLayoutDepth = 0;
                while (tmp != null)
                {
                    ++rootLayoutDepth;
                    tmp = VisualTreeHelper.GetParent(tmp);
                }

                _maxDepth = (200 - rootLayoutDepth) / levelLayoutDepth;
                _rootItem = new WeakReference((VisualTreeItem)root.DataContext);
            }
        }
Пример #5
0
        public bool ApplyReduceDepthFilterIfNeeded(ProperTreeViewItem curNode)
        {
            if (_pendingRoot != null)
            {
                OnRootLoaded();
            }

            if (_maxDepth == 0)
            {
                return(false);
            }

            VisualTreeItem rootItem = (VisualTreeItem)_rootItem.Target;

            if (rootItem == null)
            {
                return(false);
            }

            if (_snoopUI == null)
            {
                _snoopUI = VisualTreeHelper2.GetAncestor <SnoopUI>(this);
                if (_snoopUI == null)
                {
                    return(false);
                }
            }

            VisualTreeItem item         = (VisualTreeItem)curNode.DataContext;
            VisualTreeItem selectedItem = _snoopUI.CurrentSelection;

            if (selectedItem != null && item.Depth < selectedItem.Depth)
            {
                item = selectedItem;
            }

            if ((item.Depth - rootItem.Depth) <= _maxDepth)
            {
                return(false);
            }

            for (int i = 0; i < _maxDepth; ++i)
            {
                item = item.Parent;
            }

            _snoopUI.ApplyReduceDepthFilter(item);
            return(true);
        }
Пример #6
0
        public bool ApplyReduceDepthFilterIfNeeded(ProperTreeViewItem curNode)
        {
            if (_pendingRoot != null)
            {
                OnRootLoaded();
            }

            if (_maxDepth == 0)
            {
                return false;
            }

            VisualTreeItem rootItem = (VisualTreeItem)_rootItem.Target;
            if (rootItem == null)
            {
                return false;
            }

            if (_snoopUI == null)
            {
                _snoopUI = VisualTreeHelper2.GetAncestor<SnoopUI>(this);
                if (_snoopUI == null)
                {
                    return false;
                }
            }

            VisualTreeItem item = (VisualTreeItem)curNode.DataContext;
            VisualTreeItem selectedItem = _snoopUI.CurrentSelection;
            if (selectedItem != null && item.Depth < selectedItem.Depth)
            {
                item = selectedItem;
            }

            if ((item.Depth - rootItem.Depth) <= _maxDepth)
            {
                return false;
            }

            for (int i = 0; i < _maxDepth; ++i)
            {
                item = item.Parent;
            }

            _snoopUI.ApplyReduceDepthFilter(item);
            return true;
        }
Пример #7
0
 protected override DependencyObject GetContainerForItemOverride()
 {
     ProperTreeViewItem treeViewItem = new ProperTreeViewItem(_treeView);
     treeViewItem.Indent = this.Indent + 12;
     return treeViewItem;
 }
Пример #8
0
        private void OnRootLoaded()
        {
            // The following assumptions are made:
            // 1. The visual structure of each TreeViewItem is the same regardless of its location.
            // 2. The control template of a TreeViewItem contains ItemsPresenter.
            ProperTreeViewItem root = _pendingRoot;

            _pendingRoot = null;
            root.Loaded -= OnRootLoaded;

            ItemsPresenter itemsPresenter = null;
            VisualTreeHelper2.EnumerateTree(root, null,
                delegate(Visual visual, object misc)
                {
                    itemsPresenter = visual as ItemsPresenter;
                    if (itemsPresenter != null && itemsPresenter.TemplatedParent == root)
                    {
                        return HitTestResultBehavior.Stop;
                    }
                    else
                    {
                        itemsPresenter = null;
                        return HitTestResultBehavior.Continue;
                    }
                },
                null);

            if (itemsPresenter != null)
            {
                int levelLayoutDepth = 2;
                DependencyObject tmp = itemsPresenter;
                while (tmp != root)
                {
                    ++levelLayoutDepth;
                    tmp = VisualTreeHelper.GetParent(tmp);
                }

                int rootLayoutDepth = 0;
                while (tmp != null)
                {
                    ++rootLayoutDepth;
                    tmp = VisualTreeHelper.GetParent(tmp);
                }

                _maxDepth = (240 - rootLayoutDepth) / levelLayoutDepth;
                _rootItem = new WeakReference((VisualTreeItem)root.DataContext);
            }
        }