/// <summary> /// </summary> public static class ExtensionMethods { public static void ExpandAll(this System.Windows.Controls.TreeView treeView) { ExpandAllItems(treeView); } private static void ExpandAllItems(ItemsControl control) { if (control == null) { return; } foreach (Object item in control.Items) { System.Windows.Controls.TreeViewItem treeItem = control.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem; if (treeItem == null || !treeItem.HasItems) { continue; } treeItem.IsExpanded = true; treeItem.UpdateLayout(); ExpandAllItems(treeItem as ItemsControl); } } }
转载于:https://www.cnblogs.com/andrewyu/p/3207559.html