1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <ControlTemplate TargetType="TreeViewItem">
<Grid>
<!--The leftmost column contains the item's content.-->
<!--The rightmost column contains the item's children.-->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- This Border and ContentPresenter displays the content of the TreeViewItem. -->
<Border Name="Bd" BorderThickness="0.6" Padding="2" CornerRadius="4"
Background="{TemplateBinding Background}" BorderBrush="{StaticResource ItemBorderBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="19"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ToggleButton Grid.Column="0" x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}"
Background="{x:Null}" BorderBrush="Transparent" ClickMode="Press"
IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/>
<ContentPresenter Grid.Column="1" Name="PART_Header" ContentSource="Header" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Border>
<!-- The ItemsPresenter displays the item's children. -->
<ItemsPresenter x:Name="ItemsHost" Grid.Column="1" />
</Grid>
<ControlTemplate.Triggers>
<!--When the item is selected in the TreeView, use the "selected" colors and give it a drop shadow. -->
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{StaticResource SelectedItemAreaBrush}"/>
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource SelectedItemBorderBrush}"/>
<Setter TargetName="Bd" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
</Trigger>
<Trigger Property="IsExpanded" Value="false">
<Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="HasItems" Value="False">
<Setter TargetName="Expander" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate> |
Partager