我试图从树视图中删除节点标志+ - 并用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>
我需要删除+ - 图标并让扩展器工作。你能否告诉我如何完成这项工作。谢谢。
答案 0 :(得分: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>
答案 1 :(得分:3)
在ItemContainerStyle
为Template
设置新的TreeViewItems
。