/// <summary> /// 选中所有展开的节点 /// </summary> public void SelectAllExpandChildren() { if (Items != null && Items.Count > 0) { if (!IsExpanded) { IsExpanded = true; } foreach (var item in Items) { if (item is MultiSelectionTreeViewItem) { (item as MultiSelectionTreeViewItem).SelectAllExpandChildren(); } else { MultiSelectionTreeViewItem tvi = this.ItemContainerGenerator.ContainerFromItem(item) as MultiSelectionTreeViewItem; if (tvi != null) { if (tvi.ItemContainerGenerator.Status != System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) { tvi.UpdateLayout(); } tvi.SelectAllExpandChildren(); } } } } if (IsSelected != true) { IsSelected = true; } //TODO: ParentTreeView.OnSelectionChnanged(this); }
/// <summary> /// 取消所有子节点的选中 /// </summary> public void UnSelectAllChildren() { if (Items != null && Items.Count > 0) { foreach (var item in Items) { if (item is MultiSelectionTreeViewItem) { (item as MultiSelectionTreeViewItem).UnSelectAllChildren(); } else { MultiSelectionTreeViewItem tvi = this.ItemContainerGenerator.ContainerFromItem(item) as MultiSelectionTreeViewItem; if (tvi != null) { tvi.UnSelectAllChildren(); } } } } if (IsSelected != false) { IsSelected = false; } //TODO: ParentTreeView.OnSelectionChnanged(this); }