gpt4 book ai didi

c# - 使用 WPF-MVVM 在运行时展开所有 WPF TreeView 节点

转载 作者:行者123 更新时间:2023-12-03 10:36:12 31 4
gpt4 key购买 nike

我想在用户设置 CheckBox 时展开所有 TreeView 项目我能够在应用程序启动时使用 style 做到这一点:

       <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 ;

但它没有用。任何机构都知道如何做这样的事情?

最佳答案

只需绑定(bind) TreeViewItem.IsExpandedCheckBox.IsChecked .注意,你必须使用转换器来转换 bool?bool .

关于c# - 使用 WPF-MVVM 在运行时展开所有 WPF TreeView 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27439460/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com