我希望在用户设置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 ;
但它不起作用。任何人都知道如何做这样的事情?
答案 0 :(得分:1)
只需将TreeViewItem.IsExpanded
绑定到CheckBox.IsChecked
即可。请注意,您必须使用转换器将bool?
转换为bool
。