コード例 #1
0
ファイル: TreeViewEx.cs プロジェクト: nilavghosh/VChk
 protected TreeViewItem FindItemNodeInChildren(TreeViewItem parent, object item)
 {
     TreeViewItem node = null;
     bool isExpanded = parent.IsExpanded;
     if (!isExpanded) //Can't find child container unless the parent node is Expanded once
     {
         parent.IsExpanded = true;
         parent.UpdateLayout();
     }
     foreach (object data in parent.Items)
     {
         node = parent.ItemContainerGenerator.ContainerFromItem(data) as TreeViewItem;
         if (node != null)
         {
             if (data == item)
                 break;
             node = FindItemNodeInChildren(node, item);
             if (node != null)
                 break;
         }
     }
     if (node == null && parent.IsExpanded != isExpanded)
         parent.IsExpanded = isExpanded;
     if (node != null)
         parent.IsExpanded = true;
     return node;
 }
コード例 #2
0
        private static bool SelectItem(object o, TreeViewItem parentItem)
        {
            if (parentItem == null)
                return false;

            bool isExpanded = parentItem.IsExpanded;
            if (!isExpanded)
            {
                parentItem.IsExpanded = true;
                parentItem.UpdateLayout();
            }

            TreeViewItem item = parentItem.ItemContainerGenerator.ContainerFromItem(o) as TreeViewItem;
            if (item != null)
            {
                item.IsSelected = true;
                return true;
            }

            bool wasFound = false;
            for (int i = 0; i < parentItem.Items.Count; i++)
            {
                TreeViewItem itm = parentItem.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
                var found = SelectItem(o, itm);
                if (!found)
                    itm.IsExpanded = false;
                else
                    wasFound = true;
            }

            return wasFound;
        }
コード例 #3
0
        /// <summary>
        /// Recursively & syncronously expand all the nodes in this subtree.
        /// </summary>
        private static void ExpandRecursive(TreeViewItem item)
        {
            if (item == null)
            {
                return;
            }

            // Expand the current item
            if (!item.IsExpanded)
            {
                item.SetCurrentValueInternal(IsExpandedProperty, BooleanBoxes.TrueBox);
            }

            // ApplyTemplate in order to generate the ItemsPresenter and the ItemsPanel. Note that in the
            // virtualizing case even if the item is marked expanded we still need to do this step in order to
            // regenerate the visuals because they may have been virtualized away.

            item.ApplyTemplate();
            ItemsPresenter itemsPresenter = (ItemsPresenter)item.Template.FindName(ItemsHostPartName, item);

            if (itemsPresenter != null)
            {
                itemsPresenter.ApplyTemplate();
            }
            else
            {
                item.UpdateLayout();
            }

            VirtualizingPanel virtualizingPanel = item.ItemsHost as VirtualizingPanel;

            item.ItemsHost.EnsureGenerator();

            for (int i = 0, count = item.Items.Count; i < count; i++)
            {
                TreeViewItem subitem;
                if (virtualizingPanel != null)
                {
                    // We need to bring the item into view so that the container will be generated.
                    virtualizingPanel.BringIndexIntoView(i);

                    subitem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
                }
                else
                {
                    subitem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);

                    // We dont actually need to bring this into view, but we'll do it
                    // anyways to maintain the same behavior as with a virtualizing panel.
                    subitem.BringIntoView();
                }

                if (subitem != null)
                {
                    ExpandRecursive(subitem);
                }
            }
        }
コード例 #4
0
        // Token: 0x06005934 RID: 22836 RVA: 0x0018A638 File Offset: 0x00188838
        private static void ExpandRecursive(TreeViewItem item)
        {
            if (item == null)
            {
                return;
            }
            if (!item.IsExpanded)
            {
                item.SetCurrentValueInternal(TreeViewItem.IsExpandedProperty, BooleanBoxes.TrueBox);
            }
            item.ApplyTemplate();
            ItemsPresenter itemsPresenter = (ItemsPresenter)item.Template.FindName("ItemsHost", item);

            if (itemsPresenter != null)
            {
                itemsPresenter.ApplyTemplate();
            }
            else
            {
                item.UpdateLayout();
            }
            VirtualizingPanel virtualizingPanel = item.ItemsHost as VirtualizingPanel;

            item.ItemsHost.EnsureGenerator();
            int i     = 0;
            int count = item.Items.Count;

            while (i < count)
            {
                TreeViewItem treeViewItem;
                if (virtualizingPanel != null)
                {
                    virtualizingPanel.BringIndexIntoView(i);
                    treeViewItem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
                }
                else
                {
                    treeViewItem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
                    treeViewItem.BringIntoView();
                }
                if (treeViewItem != null)
                {
                    TreeViewItem.ExpandRecursive(treeViewItem);
                }
                i++;
            }
        }
コード例 #5
0
ファイル: TreeViewItem.cs プロジェクト: sjyanxin/WPFSource
        /// <summary>
        /// Recursively & syncronously expand all the nodes in this subtree. 
        /// </summary> 
        private static void ExpandRecursive(TreeViewItem item)
        { 
            if (item == null)
            {
                return;
            } 

            // Expand the current item 
            if (!item.IsExpanded) 
            {
                item.SetCurrentValueInternal(IsExpandedProperty, BooleanBoxes.TrueBox); 
            }

            // ApplyTemplate in order to generate the ItemsPresenter and the ItemsPanel. Note that in the
            // virtualizing case even if the item is marked expanded we still need to do this step in order to 
            // regenerate the visuals because they may have been virtualized away.
 
            item.ApplyTemplate(); 
            ItemsPresenter itemsPresenter = (ItemsPresenter)item.Template.FindName("ItemsHost", item);
            if (itemsPresenter != null) 
            {
                itemsPresenter.ApplyTemplate();
            }
            else 
            {
                item.UpdateLayout(); 
            } 

            VirtualizingPanel virtualizingPanel = item.ItemsHost as VirtualizingPanel; 
            item.ItemsHost.EnsureGenerator();

            for (int i = 0, count = item.Items.Count; i < count; i++)
            { 
                TreeViewItem subitem;
                if (virtualizingPanel != null) 
                { 
                    // We need to bring the item into view so that the container will be generated.
                    virtualizingPanel.BringIndexIntoView(i); 

                    subitem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
                }
                else 
                {
                    subitem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i); 
 
                    // We dont actually need to bring this into view, but we'll do it
                    // anyways to maintain the same behavior as with a virtualizing panel. 
                    subitem.BringIntoView();
                }

                if (subitem != null) 
                {
                    ExpandRecursive(subitem); 
                } 
            }
        } 
コード例 #6
0
        /// <summary>
        /// An 'Items.Refresh' call erases all the previous expansion data. This recursive
        /// method complements 'CheckExpansion' method where it does the expansion of items
        /// that were expanded before the refresh method closed them.
        /// </summary>
        /// <param name="dataVal">
        /// The Observable Collection that holds all the data for the level below. 
        /// Each InspectionData.Derivations is also an Observable Collection.
        /// </param>
        /// <param name="parent">
        /// If parent is null, it means there is no parent and it is the top level data.
        /// Otherwise, send the parent item of the dataVal parameter
        /// </param>
        private void DoExpansion(ICollection<InspectionData> dataVal, TreeViewItem parent = null)
        {
            if (dataVal == null)
                return;

            foreach (InspectionData item in dataVal)
            {
                InspectionViewItem TLVitem;

                if (parent == null)
                    TLVitem = (InspectionViewItem)(inspectionToolTip.ItemContainerGenerator.ContainerFromItem(item));
                else
                {
                    parent.IsExpanded = true;
                    parent.UpdateLayout();
                    TLVitem = (InspectionViewItem)(parent.ItemContainerGenerator.ContainerFromItem(item));
                }

                if (item.IsExpanded)
                {
                    if (null != TLVitem)
                    {
                        TLVitem.IsExpanded = true;
                    }
                }
                if (item.HasItems && item.IsExpanded)
                {
                    DoExpansion(item.Derivations, TLVitem);
                }
            }
        }