[英]Expand All WPF TreeView Nodes At Runtime Using WPF-MVVM
當用戶設置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 ;
但這沒用。 任何人都知道該怎么做?
只需將TreeViewItem.IsExpanded
綁定到CheckBox.IsChecked
。 注意,必須使用轉換器來轉換bool?
bool
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.