Reputation: 1412
I am trying to remove the node signs +- from tree view and replace them with Expander. Following is my 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>
I need to remove the +- icons and get the expander to work. Could you please advice how to get this done. Thank you.
Upvotes: 1
Views: 7726
Reputation: 10865
Play with this and modify it to satisfy your needs.
<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>
Upvotes: 4
Reputation: 184544
In the ItemContainerStyle
set a new Template
for the TreeViewItems
.
Upvotes: 3