0

如何将 ViewModel 的属性绑定到 a 中的元素HierarchicalDataTemplateTreeview该属性不在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>

4

1 回答 1

1
<CheckBox IsChecked="{Binding IsChecked}" Visibility="{Binding DataContext.IsCheckBoxVisible, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Converter={StaticResource debuger}}"/> 

使用DataContext.IsCheckBoxVisible. 希望这会奏效

于 2012-07-03T06:22:10.033 回答