Пример #1
0
        public void CollapseAll()
        {
            if (Items.Count == 0)
            {
                return;
            }

            TreeViewItem root      = (TreeViewItem)Items[0];
            var          allChilds = root.AsDepthFirstEnumerable(
                x => x.Items.Cast <TreeViewItem>());

            foreach (TreeViewItem treeViewItem in allChilds)
            {
                treeViewItem.IsExpanded = false;
            }
        }
Пример #2
0
        private void displayNavigator(XPathNodeIterator xpi)
        {
            if ((xpi != null) && (xpi.Count > 0))
            {
                for (bool hasNext = xpi.MoveNext(); hasNext; hasNext = xpi.MoveNext())
                {
                    // IXmlLineInfo lineInfo = xpi.Current as IXmlLineInfo;

                    switch (xpi.Current.NodeType)
                    {
                    case XPathNodeType.Text:
                    {
                        TreeViewItem node = new TreeViewItem();
                        node.Header     = xpi.Current.Value;
                        node.Foreground = Brushes.Brown;
                        node.ToolTip    = "(Nodeset/Text)";
                        _treeResult.Items.Add(node);
                        break;
                    }

                    case XPathNodeType.Attribute:
                    {
                        TreeViewItem node = new TreeViewItem();
                        node.Header     = "@" + xpi.Current.Name + ": " + xpi.Current.Value;
                        node.Foreground = Brushes.Brown;
                        node.ToolTip    = "(Nodeset/Attribute)";
                        node.Tag        = xpi.Current.Clone();
                        _treeResult.Items.Add(node);
                        break;
                    }

                    case XPathNodeType.Element:
                    {
                        var          document = new XSDocument(xpi.Current.OuterXml);
                        ViewerNode   vNode    = new ViewerNode(document);
                        TreeViewItem tvi      = TreeViewHelper.BuildTreeView(vNode);

                        //expand all to lazy-load all subitems
                        tvi.ExpandSubtree();
                        //now we can change the tags of all subitems
                        setTag(tvi, xpi.Current.Clone());
                        //collapse them again
                        var allChilds = tvi.AsDepthFirstEnumerable(
                            x => x.Items.Cast <TreeViewItem>());
                        foreach (TreeViewItem treeViewItem in allChilds)
                        {
                            treeViewItem.IsExpanded = false;
                        }

                        _treeResult.Items.Add(tvi);
                        break;
                    }
                    }
                    if (string.IsNullOrEmpty(_editorUserControl1.Text))
                    {
                        _editorUserControl1.Text = xpi.Current.OuterXml;
                    }
                    else
                    {
                        _editorUserControl1.Text = _editorUserControl1.Text + "\r\n" + xpi.Current.OuterXml;
                    }
                }
            }
            else
            {
                _treeResult.Items.Add("Nothing found.");
                _editorUserControl1.Text = "";
            }
        }