【问题标题】:Expand All WPF TreeView Nodes At Runtime Using WPF-MVVM使用 WPF-MVVM 在运行时展开所有 WPF TreeView 节点
【发布时间】:2014-12-12 08:17:38
【问题描述】:

我想在用户设置 CheckBox 时展开所有 TreeView 项,我可以在应用程序启动时使用样式:

       <TreeView.ItemContainerStyle>
                        <Style TargetType="{x:Type TreeViewItem}">
                          <Setter Property="IsExpanded" Value="True"/>
                        </Style>
       </TreeView.ItemContainerStyle> 

我在想我是否可以做这样的事情:

  <TreeView.ItemContainerStyle>
              <Style TargetType="{x:Type TreeViewItem}">
                  <Setter Property="IsExpanded" Value="{Binding ExpandAllItems }"/>
              </Style>
  </TreeView.ItemContainerStyle>

在 viewModel 中:

 public bool ExpandAllItems ;

但它没有用。有没有人知道怎么做这样的事情?

【问题讨论】:

    标签: c# wpf xaml mvvm treeview


    【解决方案1】:

    只需将TreeViewItem.IsExpanded 绑定到CheckBox.IsChecked。请注意,您必须使用转换器将bool? 转换为bool

    【讨论】:

    • 谢谢,它可以工作,但是当用户折叠任何节点时,即使取消选中并重新选中复选框,它仍然会折叠是否知道如何修复它?
    猜你喜欢
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多