TreeView.xaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. mc:Ignorable="d">
  7. <SolidColorBrush x:Key="TreeView_BG_MouseOver" Color="#FFD6DCE5"/>
  8. <SolidColorBrush x:Key="TreeView_BG_Select" Color="#FF47A2E7"/>
  9. <Style x:Key="TreeViewItemFocusVisual"/>
  10. <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
  11. <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
  12. <Setter Property="Focusable" Value="False"/>
  13. <Setter Property="Width" Value="16"/>
  14. <Setter Property="Height" Value="16"/>
  15. <Setter Property="Template">
  16. <Setter.Value>
  17. <ControlTemplate TargetType="{x:Type ToggleButton}">
  18. <Border Background="#00FFFFFF" Width="16" Height="16" Padding="3,0" Cursor="Hand">
  19. <Grid>
  20. <Grid Background="Black" Margin="-5" Opacity="0"/>
  21. <Path x:Name="ExpandPath" Fill="Gray" Data="{StaticResource TreeArrow}" HorizontalAlignment="Left" VerticalAlignment="Center">
  22. <Path.RenderTransform>
  23. <RotateTransform Angle="135" CenterX="3" CenterY="3"/>
  24. </Path.RenderTransform>
  25. </Path>
  26. </Grid>
  27. </Border>
  28. <ControlTemplate.Triggers>
  29. <Trigger Property="IsMouseOver" Value="True">
  30. <Setter Property="Fill" TargetName="ExpandPath" Value="#FFFFBB00"/>
  31. </Trigger>
  32. <Trigger Property="IsChecked" Value="True">
  33. <Setter Property="RenderTransform" TargetName="ExpandPath">
  34. <Setter.Value>
  35. <RotateTransform Angle="180" CenterX="3" CenterY="3"/>
  36. </Setter.Value>
  37. </Setter>
  38. <Setter Property="Fill" TargetName="ExpandPath" Value="Black"/>
  39. </Trigger>
  40. <Trigger Property="IsEnabled" Value="false">
  41. <Setter Property="Fill" TargetName="ExpandPath" Value="#FF9A9A9A"/>
  42. </Trigger>
  43. </ControlTemplate.Triggers>
  44. </ControlTemplate>
  45. </Setter.Value>
  46. </Setter>
  47. </Style>
  48. <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}">
  49. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  50. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  51. <Setter Property="Padding" Value="1,0,0,0"/>
  52. <Setter Property="FontFamily" Value="Arial"/>
  53. <Setter Property="Background" Value="{DynamicResource TreeView_BG_MouseOver}"/>
  54. <Setter Property="Foreground" Value="{DynamicResource FG_Black}"/>
  55. <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
  56. <Setter Property="FontSize" Value="16"/>
  57. <Setter Property="Template">
  58. <Setter.Value>
  59. <ControlTemplate TargetType="{x:Type TreeViewItem}">
  60. <Grid SnapsToDevicePixels="true">
  61. <Grid.ColumnDefinitions>
  62. <ColumnDefinition MinWidth="16" Width="Auto"/>
  63. <ColumnDefinition Width="Auto"/>
  64. <ColumnDefinition Width="*"/>
  65. </Grid.ColumnDefinitions>
  66. <Grid.RowDefinitions>
  67. <RowDefinition Height="Auto" MinHeight="24"/>
  68. <RowDefinition/>
  69. </Grid.RowDefinitions>
  70. <Border x:Name="Text_BG" Grid.ColumnSpan="3" Background="{TemplateBinding Background}" Margin="-2,2,1,1" Opacity="0"/>
  71. <ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/>
  72. <Grid x:Name="TreeViewHeader" Grid.Column="1" HorizontalAlignment="Left" Cursor="Hand">
  73. <ContentPresenter x:Name="PART_Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" VerticalAlignment="Center" Margin="2,0,5,0"/>
  74. </Grid>
  75. <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="1"/>
  76. </Grid>
  77. <ControlTemplate.Triggers>
  78. <Trigger Property="IsMouseOver" SourceName="TreeViewHeader" Value="True">
  79. <Setter Property="Opacity" TargetName="Text_BG" Value="1"/>
  80. <Setter Property="Foreground" Value="{DynamicResource FG_Blue}"/>
  81. </Trigger>
  82. <Trigger Property="IsSelected" Value="True">
  83. <Setter Property="BorderThickness" TargetName="Text_BG" Value="0"/>
  84. <Setter Property="Opacity" TargetName="Text_BG" Value="1"/>
  85. <Setter Property="Foreground" Value="{DynamicResource FG_White}"/>
  86. <Setter Property="Background" TargetName="Text_BG" Value="{DynamicResource TreeView_BG_Select}"/>
  87. </Trigger>
  88. <Trigger Property="IsExpanded" Value="false">
  89. <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
  90. </Trigger>
  91. <Trigger Property="HasItems" Value="false">
  92. <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
  93. </Trigger>
  94. <Trigger Property="IsEnabled" Value="false">
  95. <Setter Property="Foreground" Value="#FF9A9A9A"/>
  96. </Trigger>
  97. </ControlTemplate.Triggers>
  98. </ControlTemplate>
  99. </Setter.Value>
  100. </Setter>
  101. <Style.Triggers>
  102. <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
  103. <Setter Property="ItemsPanel">
  104. <Setter.Value>
  105. <ItemsPanelTemplate>
  106. <VirtualizingStackPanel/>
  107. </ItemsPanelTemplate>
  108. </Setter.Value>
  109. </Setter>
  110. </Trigger>
  111. </Style.Triggers>
  112. </Style>
  113. <Style x:Key="TreeView-SecondFloor" TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
  114. <Setter Property="FontSize" Value="14"/>
  115. </Style>
  116. <Style x:Key="{x:Type TreeView}" TargetType="{x:Type TreeView}">
  117. <Setter Property="Background" Value="Transparent"/>
  118. <Setter Property="OverridesDefaultStyle" Value="True"/>
  119. <Setter Property="SnapsToDevicePixels" Value="True"/>
  120. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
  121. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
  122. <Setter Property="Template">
  123. <Setter.Value >
  124. <ControlTemplate TargetType="{x:Type TreeView}" >
  125. <Border x:Name = "Border" CornerRadius="1" BorderThickness="1">
  126. <ScrollViewer Focusable="False" CanContentScroll="False" Padding="4">
  127. <ItemsPresenter/>
  128. </ScrollViewer>
  129. </Border>
  130. </ControlTemplate>
  131. </Setter.Value>
  132. </Setter>
  133. </Style>
  134. <Style x:Key="TreeViewItemExtend" TargetType="{x:Type TreeViewItem}">
  135. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  136. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  137. <Setter Property="Padding" Value="1,0,0,0"/>
  138. <Setter Property="FontFamily" Value="Arial"/>
  139. <Setter Property="Background" Value="{DynamicResource TreeView_BG_MouseOver}"/>
  140. <Setter Property="Foreground" Value="{DynamicResource FG_Black}"/>
  141. <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
  142. <Setter Property="FontSize" Value="16"/>
  143. <Setter Property="Template">
  144. <Setter.Value>
  145. <ControlTemplate TargetType="{x:Type TreeViewItem}">
  146. <Grid SnapsToDevicePixels="true">
  147. <Grid.ColumnDefinitions>
  148. <ColumnDefinition MinWidth="16" Width="Auto"/>
  149. <ColumnDefinition Width="Auto"/>
  150. <ColumnDefinition Width="*"/>
  151. </Grid.ColumnDefinitions>
  152. <Grid.RowDefinitions>
  153. <RowDefinition Height="Auto" MinHeight="24"/>
  154. <RowDefinition/>
  155. </Grid.RowDefinitions>
  156. <Border x:Name="Text_BG" Grid.Column="1" Background="{TemplateBinding Background}" Margin="-2,2,1,1" Opacity="0"/>
  157. <ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/>
  158. <Grid x:Name="TreeViewHeader" Grid.Column="1" HorizontalAlignment="Left" Cursor="Hand">
  159. <ContentPresenter x:Name="PART_Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" VerticalAlignment="Center" Margin="2,0,5,0"/>
  160. </Grid>
  161. <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="1"/>
  162. </Grid>
  163. <ControlTemplate.Triggers>
  164. <Trigger Property="IsMouseOver" SourceName="TreeViewHeader" Value="True">
  165. <Setter Property="Opacity" TargetName="Text_BG" Value="1"/>
  166. <Setter Property="Foreground" Value="{DynamicResource FG_Blue}"/>
  167. </Trigger>
  168. <Trigger Property="IsSelected" Value="True">
  169. <Setter Property="FontWeight" Value="Bold"></Setter>
  170. <Setter Property="BorderThickness" TargetName="Text_BG" Value="0"/>
  171. <Setter Property="Opacity" TargetName="Text_BG" Value="1"/>
  172. <Setter Property="Background" TargetName="Text_BG" Value="{DynamicResource TreeView_BG_Select}"/>
  173. </Trigger>
  174. <Trigger Property="IsExpanded" Value="false">
  175. <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
  176. </Trigger>
  177. <Trigger Property="HasItems" Value="false">
  178. <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
  179. </Trigger>
  180. <Trigger Property="IsEnabled" Value="false">
  181. <Setter Property="Foreground" Value="#FF9A9A9A"/>
  182. </Trigger>
  183. </ControlTemplate.Triggers>
  184. </ControlTemplate>
  185. </Setter.Value>
  186. </Setter>
  187. <Style.Triggers>
  188. <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
  189. <Setter Property="ItemsPanel">
  190. <Setter.Value>
  191. <ItemsPanelTemplate>
  192. <VirtualizingStackPanel/>
  193. </ItemsPanelTemplate>
  194. </Setter.Value>
  195. </Setter>
  196. </Trigger>
  197. </Style.Triggers>
  198. </Style>
  199. </ResourceDictionary>