1

我正在尝试从树视图中删除节点符号 +- 并用 Expander 替换它们。以下是我的 Xaml:

        <TreeView.Resources>
            <HierarchicalDataTemplate ItemsSource="{Binding Disks}" DataType="{x:Type local1:GenSet}">
                <Expander Header="{Binding Genre}" x:Name="exp" IsExpanded="False" >
                </Expander>
                <HierarchicalDataTemplate.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=IsExpanded}" Value="True">
                        <Setter TargetName="exp" Property="IsExpanded"  Value="True"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=IsExpanded}" Value="False">
                        <Setter TargetName="exp" Property="IsExpanded"  Value="False"/>
                    </DataTrigger>
                </HierarchicalDataTemplate.Triggers>

                <!--<TextBlock Text="{Binding Genre}"/>-->
            </HierarchicalDataTemplate>
            <DataTemplate DataType="{x:Type local1:DiskPrime}">
                <TextBlock Text="{Binding Namee}"/>
            </DataTemplate>
        </TreeView.Resources>
    </TreeView>

我需要删除 +- 图标并让扩展器工作。您能否建议如何完成这项工作。谢谢你。

4

2 回答 2

4

玩这个并修改它以满足您的需求。

     <TreeView>
         <TreeView.Resources> 
           <Style TargetType="TreeViewItem">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Expander Header="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=Header}">
                                <ContentPresenter Content="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=Items[0]}"/>
                            </Expander>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </TreeView.Resources>
        <TreeViewItem Header="Test 1">
            <TreeViewItem Header="Child 1"><TextBox Text="Hello"></TextBox></TreeViewItem>
        </TreeViewItem>
        <TreeViewItem Header="Test 2"/>
        <TreeViewItem Header="Test 3"/>
     </TreeView>
于 2012-08-05T20:51:32.237 回答
3

ItemContainerStyle设置一个新TemplateTreeViewItems

于 2012-08-05T10:11:54.257 回答