【问题标题】:WPF Tree View - Clicking any where on the root node should expand the child nodeWPF 树视图 - 单击根节点上的任何位置应展开子节点
【发布时间】:2014-03-26 01:46:26
【问题描述】:

我正在使用分层数据来填充树视图。单击根节点的三角形图标将展开/折叠子节点。 我想要这种行为:当我单击根节点上的任意位置时,它应该展开/折叠子节点。它应该在展开/折叠之间切换。

我怎样才能做到这一点?提前致谢。

【问题讨论】:

  • 你尝试过任何编码吗?

标签: c# wpf xaml


【解决方案1】:

试试这个

<TreeView TreeViewItem.Selected="TreeViewItem_Selected"/>

在 xaml.cs 中

private void TreeViewItem_Selected(object sender, RoutedEventArgs e)
{
   TreeViewItem tvi = (TreeViewItem)e.OriginalSource;
   if (tvi != null)
      tvi.IsExpanded = !tvi.IsExpanded;
}

参考:WPF expand TreeView on single mouse clickHow to expand WPF TreeView on single click of item

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-22
  • 2013-07-13
  • 1970-01-01
  • 2023-01-13
相关资源
最近更新 更多