WPF TreeView节点的展开和收缩
Posted wxstar8
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF TreeView节点的展开和收缩相关的知识,希望对你有一定的参考价值。
1、实现TreeView所有节点的展开和收缩
/// <summary>
////// </summary>
/// <param name="control">TreeView控件</param>
/// <param name="expandNode">true:展开 false:收缩</param>
private void SetNodeExpandedState(ItemsControl control, bool expandNode)
try
if (control != null)
foreach (object item in control.Items)
TreeViewItem treeItem = control.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
if (treeItem != null && treeItem.HasItems)
treeItem.IsExpanded = expandNode;
if (treeItem.ItemContainerGenerator.Status != System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)treeItem.UpdateLayout();
SetNodeExpandedState(treeItem as ItemsControl, expandNode);
catch (Exception ex)
Eastups.Utility.Logger.Write(LogType.Error, ex.Message.ToString());
以上是关于WPF TreeView节点的展开和收缩的主要内容,如果未能解决你的问题,请参考以下文章
ASP中关于TreeView控件的问题,怎样展开、收缩所有子节点?
关于c#中treeview节点的收缩与展开(.net web)
.net中如何使treeview只让选中节点展开,其它节点收缩