TreeViewItemStyle.xaml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  3. <SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Stroke" Color="#FF818181"/>
  4. <SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Fill" Color="#FFFFFFFF"/>
  5. <SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Stroke" Color="#FF27C7F7"/>
  6. <SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Fill" Color="#FFCCEEFB"/>
  7. <SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Stroke" Color="#FF262626"/>
  8. <SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Fill" Color="#FF595959"/>
  9. <SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Stroke" Color="#FF1CC4F7"/>
  10. <SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Fill" Color="#FF82DFFB"/>
  11. <SolidColorBrush x:Key="TreeViewItem.Selected.Background" Color="#F2F2F2"/>
  12. <SolidColorBrush x:Key="TreeViewItem.Selected.Foreground" Color="#666666"/>
  13. <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
  14. <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
  15. <Setter Property="Focusable" Value="False"/>
  16. <Setter Property="Width" Value="16"/>
  17. <Setter Property="Height" Value="16"/>
  18. <Setter Property="Template">
  19. <Setter.Value>
  20. <ControlTemplate TargetType="{x:Type ToggleButton}">
  21. <Border Background="Transparent" Height="16" Padding="5,5,5,5" Width="16">
  22. <Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="{StaticResource TreeViewItem.TreeArrow.Static.Fill}" Stroke="{StaticResource TreeViewItem.TreeArrow.Static.Stroke}">
  23. <Path.RenderTransform>
  24. <RotateTransform Angle="135" CenterY="3" CenterX="3"/>
  25. </Path.RenderTransform>
  26. </Path>
  27. </Border>
  28. <ControlTemplate.Triggers>
  29. <Trigger Property="IsChecked" Value="True">
  30. <Setter Property="RenderTransform" TargetName="ExpandPath">
  31. <Setter.Value>
  32. <RotateTransform Angle="180" CenterY="3" CenterX="3"/>
  33. </Setter.Value>
  34. </Setter>
  35. <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Fill}"/>
  36. <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Stroke}"/>
  37. </Trigger>
  38. <Trigger Property="IsMouseOver" Value="True">
  39. <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Stroke}"/>
  40. <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Fill}"/>
  41. </Trigger>
  42. <MultiTrigger>
  43. <MultiTrigger.Conditions>
  44. <Condition Property="IsMouseOver" Value="True"/>
  45. <Condition Property="IsChecked" Value="True"/>
  46. </MultiTrigger.Conditions>
  47. <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Stroke}"/>
  48. <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Fill}"/>
  49. </MultiTrigger>
  50. </ControlTemplate.Triggers>
  51. </ControlTemplate>
  52. </Setter.Value>
  53. </Setter>
  54. </Style>
  55. <Style x:Key="TreeViewItemFocusVisual">
  56. <Setter Property="Control.Template">
  57. <Setter.Value>
  58. <ControlTemplate>
  59. <Rectangle/>
  60. </ControlTemplate>
  61. </Setter.Value>
  62. </Setter>
  63. </Style>
  64. <Style x:Key="TreeViewItemStyle" TargetType="{x:Type TreeViewItem}">
  65. <Setter Property="Background" Value="Transparent"/>
  66. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  67. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  68. <Setter Property="Padding" Value="1,0,0,0"/>
  69. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
  70. <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
  71. <Setter Property="Template">
  72. <Setter.Value>
  73. <ControlTemplate TargetType="{x:Type TreeViewItem}">
  74. <Grid>
  75. <Grid.ColumnDefinitions>
  76. <ColumnDefinition MinWidth="19" Width="Auto"/>
  77. <ColumnDefinition Width="*"/>
  78. </Grid.ColumnDefinitions>
  79. <Grid.RowDefinitions>
  80. <RowDefinition Height="Auto"/>
  81. <RowDefinition/>
  82. </Grid.RowDefinitions>
  83. <Border x:Name="groupBorder" Grid.Column="0" Grid.ColumnSpan="2">
  84. <Grid>
  85. <Grid.ColumnDefinitions>
  86. <ColumnDefinition MinWidth="19" Width="Auto"/>
  87. <ColumnDefinition Width="*"/>
  88. </Grid.ColumnDefinitions>
  89. <ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ExpandCollapseToggleStyle}"/>
  90. <Border x:Name="Bd" Height="32" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.Column="1" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
  91. <ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  92. VerticalAlignment="Center"/>
  93. </Border>
  94. </Grid>
  95. <Border.Style>
  96. <Style TargetType="Border">
  97. <Style.Triggers>
  98. <Trigger Property="IsMouseOver" Value="True">
  99. <Setter Property="Background" Value="{StaticResource TreeViewItem.Selected.Background}"/>
  100. </Trigger>
  101. </Style.Triggers>
  102. </Style>
  103. </Border.Style>
  104. </Border>
  105. <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.Row="1"/>
  106. </Grid>
  107. <ControlTemplate.Triggers>
  108. <Trigger Property="IsExpanded" Value="false">
  109. <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
  110. </Trigger>
  111. <Trigger Property="HasItems" Value="false">
  112. <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
  113. </Trigger>
  114. <Trigger Property="IsSelected" Value="true">
  115. <Setter Property="Background" TargetName="Bd" Value="{StaticResource TreeViewItem.Selected.Background}"/>
  116. <Setter Property="Foreground" Value="{StaticResource TreeViewItem.Selected.Foreground}"/>
  117. <Setter Property="Background" TargetName="groupBorder" Value="{StaticResource TreeViewItem.Selected.Background}"/>
  118. </Trigger>
  119. <MultiTrigger>
  120. <MultiTrigger.Conditions>
  121. <Condition Property="IsSelected" Value="true"/>
  122. <Condition Property="IsSelectionActive" Value="false"/>
  123. </MultiTrigger.Conditions>
  124. <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
  125. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}}"/>
  126. </MultiTrigger>
  127. <Trigger Property="IsEnabled" Value="false">
  128. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
  129. </Trigger>
  130. </ControlTemplate.Triggers>
  131. </ControlTemplate>
  132. </Setter.Value>
  133. </Setter>
  134. <Style.Triggers>
  135. <Trigger Property="VirtualizingPanel.IsVirtualizing" Value="true">
  136. <Setter Property="ItemsPanel">
  137. <Setter.Value>
  138. <ItemsPanelTemplate>
  139. <VirtualizingStackPanel/>
  140. </ItemsPanelTemplate>
  141. </Setter.Value>
  142. </Setter>
  143. </Trigger>
  144. </Style.Triggers>
  145. </Style>
  146. </ResourceDictionary>