更新时间:2021-12-20 07:37:04
对于你的问题,假设所有的孩子都是相同的类型.. 只需在你的窗口资源中定义一个 HierarchicalDataTemplate
任何 x:key
并放置 DataType
这是你的 Child 对象的类型......你的整个树将填充..
For your problem, assuming all the childs are of same type.. just define one HierarchicalDataTemplate
in your window's resources without any x:key
and put the DataType
which is type of your Child object...Your whole tree will populate..
<HierarchicalDataTemplate DataType="{local:YourParentType}"
ItemsSource="{Binding Childs}">
<CheckBox IsChecked="{Binding isChecked}" Content="{Binding naam}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{local:YourChildType}"
ItemsSource="{Binding Childs}">
<CheckBox IsChecked="{Binding isChecked}" Content="{Binding naam}" />
</HierarchicalDataTemplate>
这里假设 local 是定义您的 Child 类的命名空间 (xmlns)
here assuming local is the namespace (xmlns) in which your Child class is defined