TreeViewStyle.xaml 8.28 KB
<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
	<Style x:Key="TreeViewItemFocusVisual">
		<Setter Property="Control.Template">
			<Setter.Value>
				<ControlTemplate>
					<Rectangle/>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
	<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
		<Setter Property="Focusable" Value="False"/>
		<Setter Property="Width" Value="16"/>
		<Setter Property="Height" Value="16"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ToggleButton}">
					<Border Background="Transparent" Height="16" Padding="5,5,5,5" Width="16">
						<Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="Transparent" Stroke="#FF989898">
							<Path.RenderTransform>
								<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
							</Path.RenderTransform>
						</Path>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsMouseOver" Value="True">
							<Setter Property="Stroke" TargetName="ExpandPath" Value="{DynamicResource ButtonCheckedBrush}"/>
							<Setter Property="Fill" TargetName="ExpandPath" Value="{DynamicResource ButtonDefaultStateBackground}"/>
						</Trigger>
						<Trigger Property="IsChecked" Value="True">
							<Setter Property="RenderTransform" TargetName="ExpandPath">
								<Setter.Value>
									<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
								</Setter.Value>
							</Setter>
							<Setter Property="Stroke" TargetName="ExpandPath" Value="{DynamicResource ButtonNormalBorder}"/>
							<Setter Property="Fill" TargetName="ExpandPath" Value="{DynamicResource ButtonNormalBorder}"/>
						</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="5,2"/>
		<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
		<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/>
						</Grid.RowDefinitions>
						
						<ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ExpandCollapseToggleStyle}"/>

						<Grid Grid.Column="1" SnapsToDevicePixels="true">																													
								<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" 
										BorderThickness="{TemplateBinding BorderThickness}" 
										SnapsToDevicePixels="true" CornerRadius="3">
									<Grid>
										<Grid x:Name="MouseOverGrid" Visibility="Collapsed">
											<Rectangle Fill="{DynamicResource ButtonNormalBackground}" />
											<Rectangle Fill="{DynamicResource ButtonNormalBackground2}" OpacityMask="{DynamicResource TileQuadroBrushWhite}"/>
											<Rectangle Opacity="0.9" Visibility="Visible" Fill="{DynamicResource ListBoxMouseOverItemBrush}"/>								
										</Grid>
										<ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
											SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
											Margin="{TemplateBinding Padding}"/>								
									</Grid>
								</Border>														
								
							
						</Grid>
						<ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1"/>
					</Grid>
					<ControlTemplate.Triggers>
						<Trigger Property="IsExpanded" Value="false">
							<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
						</Trigger>
						<Trigger Property="HasItems" Value="false">
							<Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
						</Trigger>
						<Trigger SourceName="Bd" Property="IsMouseOver" Value="True">
							<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}"/>
							<Setter Property="BorderThickness" TargetName="Bd" Value="1"/>
							<Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource ButtonCheckedBrush}"/>
							<Setter Property="Visibility" TargetName="MouseOverGrid" Value="Visible"/>
						</Trigger>
						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="IsSelected" Value="True"/>
								<Condition Property="IsMouseOver" Value="False"/>
							</MultiTrigger.Conditions>
							<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}"/>
							<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ButtonNormalBackground}"/>
						</MultiTrigger>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Foreground" Value="{DynamicResource GrayMiddleBrush}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
		<Setter Property="BorderThickness" Value="1"/>
		<Style.Triggers>
			<Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
				<Setter Property="ItemsPanel">
					<Setter.Value>
						<ItemsPanelTemplate>
							<VirtualizingStackPanel/>
						</ItemsPanelTemplate>
					</Setter.Value>
				</Setter>
			</Trigger>
		</Style.Triggers>
	</Style>
	<Style x:Key="TreeViewStyle" TargetType="{x:Type TreeView}">
		<Setter Property="Background" Value="{DynamicResource CommonBackgroundBrush}"/>
		<Setter Property="BorderBrush" Value="{DynamicResource ButtonNormalBorder}"/>
		<Setter Property="BorderThickness" Value="1"/>
		<Setter Property="Padding" Value="1"/>
		<Setter Property="Foreground" Value="{DynamicResource ForegroundNormalColorBrush}"/>
		<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
		<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
		<Setter Property="VerticalContentAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type TreeView}">
					<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true">
						<ScrollViewer x:Name="_tv_scrollviewer_" Background="{TemplateBinding Background}" CanContentScroll="false" Focusable="false" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
							<ItemsPresenter/>
						</ScrollViewer>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
						</Trigger>
						<Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
							<Setter Property="CanContentScroll" TargetName="_tv_scrollviewer_" Value="true"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
		<Setter Property="ItemContainerStyle" Value="{DynamicResource TreeViewItemStyle}"/>
		<Style.Triggers>
			<Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
				<Setter Property="ItemsPanel">
					<Setter.Value>
						<ItemsPanelTemplate>
							<VirtualizingStackPanel/>
						</ItemsPanelTemplate>
					</Setter.Value>
				</Setter>
			</Trigger>
		</Style.Triggers>
	</Style>
	<!-- Resource dictionary entries should be defined here. -->
</ResourceDictionary>