AutoExpand treeview in WPF

前端 未结 5 2066
悲哀的现实
悲哀的现实 2021-02-06 21:04

Is there a way to automatically expand all nodes from a treeview in WPF? I searched and didn\'t even find an expand function in the treeview property.

Thanks

5条回答
  •  无人共我
    2021-02-06 21:45

    Carlo's answer was better because it opens all levels

    This improves upon that example with a little more concise code example.

        private void ExpandAllNodes(TreeViewItem treeItem)
        {
            treeItem.IsExpanded = true;  
            foreach (var childItem in treeItem.Items.OfType())
            {
                    ExpandAllNodes(childItem);
            }
        }
    

    Call it by using this line of code

    TreeViewInstance.Items.OfType().ToList().ForEach(ExpandAllNodes);
    

提交回复
热议问题