<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<StackPanel Orientation="Horizontal" Background="BurlyWood">
<Image Height="16" Width="16"
Source="/WpfApplication27;component/Images/Forward.png"></Image>
<Label Content="{TemplateBinding Header}"></Label>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel HorizontalAlignment="Center"
IsItemsHost="True" Margin="4,6" Orientation="Vertical"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
答案 0 :(得分:0)
通过设置控件模板,您完全覆盖现有控件模板,并且您的模板不再包含允许扩展子树的按钮等。
模板TreeViewItems相对复杂,请参阅this example以获取参考。