<Style x:Key=
"ExpandCollapseToggleStyle"
TargetType=
"{x:Type ToggleButton}"
>
<Setter Property=
"Focusable"
Value=
"False"
/>
<Setter Property=
"Width"
Value=
"10"
/>
<Setter Property=
"Height"
Value=
"10"
/>
<Setter Property=
"Template"
>
<Setter.Value>
<ControlTemplate TargetType=
"{x:Type ToggleButton}"
>
<Border Background=
"Transparent"
Height=
"10"
Width=
"10"
>
<Image x:Name=
"Tree_Ico"
Source=
"/VirtalWelding;component/Images/TreeHidden.jpg"
></Image>
</Border>
<ControlTemplate.Triggers>
<Trigger Property=
"IsMouseOver"
Value=
"True"
>
</Trigger>
<Trigger Property=
"IsChecked"
Value=
"True"
>
<Setter Property=
"Source"
TargetName=
"Tree_Ico"
Value=
"/VirtalWelding;component/Images/TreeShow.jpg"
></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key=
"TreeViewItemStyle"
TargetType=
"{x:Type TreeViewItem}"
>
<Setter Property=
"Background"
Value=
"Transparent"
/>
<Setter Property=
"HorizontalContentAlignment"
Value=
"{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
/>
<Setter Property=
"VerticalContentAlignment"
Value=
"{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
/>
<Setter Property=
"Padding"
Value=
"1,0,0,0"
/>
<Setter Property=
"IsExpanded"
Value=
"True"
></Setter>
<Setter Property=
"FocusVisualStyle"
Value=
"{StaticResource TreeViewItemFocusVisual}"
/>
<Setter Property=
"Template"
>
<Setter.Value>
<ControlTemplate TargetType=
"{x:Type TreeViewItem}"
>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth=
"19"
Width=
"Auto"
/>
<ColumnDefinition Width=
"Auto"
/>
<ColumnDefinition Width=
"*"
/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height=
"Auto"
/>
<RowDefinition Height=
"Auto"
/>
</Grid.RowDefinitions>
<!--<ToggleButton Panel.ZIndex=
"1"
x:Name=
"Expander"
Margin=
"2,-1,0,0"
ClickMode=
"Press"
Grid.Row=
"0"
Grid.Column=
"0"
IsChecked=
"{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
Style=
"{StaticResource ExpandCollapseToggleStyle}"
/>
<Rectangle Panel.ZIndex=
"0"
Fill=
"#949395"
Grid.Column=
"0"
Grid.Row=
"1"
Margin=
"3,-16,0,15"
HorizontalAlignment=
"Stretch"
x:Name=
"VLine"
Stroke=
"#949395"
VerticalAlignment=
"Stretch"
Width=
"1"
/>
<Border x:Name=
"Bd"
Grid.Row=
"0"
Grid.Column=
"1"
VerticalAlignment=
"Top"
BorderBrush=
"{TemplateBinding BorderBrush}"
BorderThickness=
"{TemplateBinding BorderThickness}"
Background=
"{TemplateBinding Background}"
SnapsToDevicePixels=
"true"
>
<ContentPresenter VerticalAlignment=
"Bottom"
x:Name=
"PART_Header"
TextBlock.Foreground=
"#FFCCCCCD"
TextBlock.FontSize=
"14"
ContentSource=
"Header"
HorizontalAlignment=
"{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels=
"{TemplateBinding SnapsToDevicePixels}"
/>
</Border>
<ItemsPresenter x:Name=
"ItemsHost"
Grid.ColumnSpan=
"2"
Grid.Column=
"1"
Grid.Row=
"1"
/>-->
<ToggleButton Panel.ZIndex=
"1"
x:Name=
"Expander"
Margin=
"2,-2,0,0"
ClickMode=
"Press"
Grid.Row=
"0"
Grid.Column=
"0"
IsChecked=
"{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
Style=
"{StaticResource ExpandCollapseToggleStyle}"
/>
<Rectangle Panel.ZIndex=
"0"
Grid.Column=
"0"
Margin=
"-35,-10,0,15"
Grid.Row=
"0"
Fill=
"#949395"
HorizontalAlignment=
"Stretch"
x:Name=
"VLineUp"
Stroke=
"#949395"
VerticalAlignment=
"Stretch"
Width=
"1"
/>
<Rectangle Panel.ZIndex=
"0"
Grid.Column=
"0"
Margin=
"-35,-15,0,10"
Grid.Row=
"1"
Visibility=
"{Binding NextBaseEntityTree,Converter={StaticResource VLineVisibiltyConverter}}"
Fill=
"#949395"
HorizontalAlignment=
"Stretch"
x:Name=
"VLineDown"
Stroke=
"#949395"
VerticalAlignment=
"Stretch"
Width=
"1"
/>
<Border x:Name=
"Bd"
Grid.Row=
"0"
VerticalAlignment=
"Center"
Margin=
"0,0,0,0"
Grid.Column=
"1"
BorderBrush=
"{TemplateBinding BorderBrush}"
BorderThickness=
"{TemplateBinding BorderThickness}"
Background=
"{TemplateBinding Background}"
SnapsToDevicePixels=
"true"
>
<ContentPresenter VerticalAlignment=
"Bottom"
Margin=
"0,0,0,2"
x:Name=
"PART_Header"
TextBlock.Foreground=
"#FFCCCCCD"
TextBlock.FontSize=
"14"
ContentSource=
"Header"
HorizontalAlignment=
"{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels=
"{TemplateBinding SnapsToDevicePixels}"
/>
</Border>
<ItemsPresenter x:Name=
"ItemsHost"
Margin=
"0,0,0,0"
Grid.ColumnSpan=
"2"
Grid.Column=
"1"
Grid.Row=
"1"
/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property=
"IsExpanded"
Value=
"false"
>
<Setter Property=
"Visibility"
TargetName=
"ItemsHost"
Value=
"Collapsed"
/>
<!--<Setter Property=
"Visibility"
TargetName=
"VLine"
Value=
"Hidden"
/>-->
<!--<Setter Property=
"Margin"
TargetName=
"VLine"
Value=
"3,-20,0,0"
/>-->
</Trigger>
<Trigger Property=
"IsExpanded"
Value=
"true"
>
<Setter Property=
"Visibility"
TargetName=
"ItemsHost"
Value=
"Visible"
/>
<!--<Setter Property=
"Visibility"
TargetName=
"VLine"
Value=
"Visible"
/>-->
<!--<Setter Property=
"Visibility"
TargetName=
"HLine"
Value=
"Hidden"
/>-->
</Trigger>
<Trigger Property=
"HasItems"
Value=
"false"
>
<Setter Property=
"Visibility"
TargetName=
"Expander"
Value=
"Hidden"
/>
<!--<Setter Property=
"Visibility"
TargetName=
"VLine"
Value=
"Hidden"
/>-->
<Setter Property=
"Margin"
TargetName=
"ItemsHost"
Value=
"-10,0,0,0"
></Setter>
</Trigger>
<Trigger Property=
"HasItems"
Value=
"true"
>
<!--<Setter Property=
"Visibility"
TargetName=
"HLine"
Value=
"Visible"
/>-->
</Trigger>
<Trigger Property=
"IsSelected"
Value=
"true"
>
<Setter Property=
"Background"
TargetName=
"Bd"
Value=
"#FF2D2C2D"
/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property=
"IsSelected"
Value=
"true"
/>
<Condition Property=
"IsSelectionActive"
Value=
"false"
/>
</MultiTrigger.Conditions>
</MultiTrigger>
<Trigger Property=
"IsEnabled"
Value=
"false"
>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
原文:http://www.cnblogs.com/lxdonge/p/5126619.html