如何将 ViewModel 的属性绑定到 a 中的元素HierarchicalDataTemplate
(Treeview
该属性不在HierarchicalDataTemplate.Itemsource
)
这是示例,问题在此行中:Visibility="{Binding IsCheckBoxVisible , RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Converter={StaticResource debuger}}"/>
<UserControl ....>
<Grid>
<TreeView ItemsSource="{Binding Roots}" Grid.Row="0">
<TreeView.ItemContainerStyle>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate >
<HierarchicalDataTemplate ItemsSource="{Binding ConfigedChildren}">
<StackPanel Orientation="Horizontal" >
<CheckBox IsChecked="{Binding IsChecked}" Visibility="{Binding IsCheckBoxVisible, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Converter={StaticResource debuger}}"/>
<Label Content="{Binding Title}"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>