TreeViewStyle.xaml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:converters="clr-namespace:Muchinfo.MTPClient.Converters">
  4. <converters:TreeViewLineConverter x:Key="TreeViewLineConverter" />
  5. <converters:NewTreeViewLineConverter x:Key="NewTreeViewLineConverter" />
  6. <!-- 折叠按钮 -->
  7. <Style x:Key="ExpandToggleButtonStyle" TargetType="{x:Type ToggleButton}">
  8. <Setter Property="Focusable" Value="False" />
  9. <Setter Property="Margin" Value="0,5.5,0,0" />
  10. <Setter Property="Width" Value="19" />
  11. <Setter Property="Height" Value="13" />
  12. <Setter Property="Template">
  13. <Setter.Value>
  14. <ControlTemplate TargetType="{x:Type ToggleButton}">
  15. <Border Width="19"
  16. Height="13"
  17. Background="Transparent">
  18. <Border Width="9"
  19. Height="9"
  20. Background="{DynamicResource TreeBackground}"
  21. BorderBrush="{DynamicResource TreeForeground}"
  22. BorderThickness="1"
  23. SnapsToDevicePixels="true">
  24. <Path x:Name="ExpandPath"
  25. Margin="1,1,1,1"
  26. Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z"
  27. Fill="{DynamicResource TreeForeground}" />
  28. </Border>
  29. </Border>
  30. <ControlTemplate.Triggers>
  31. <Trigger Property="IsChecked" Value="True">
  32. <Setter TargetName="ExpandPath" Property="Data" Value="M 0 2 L 0 3 L 5 3 L 5 2 Z" />
  33. </Trigger>
  34. <Trigger Property="IsMouseOver" Value="True">
  35. <Setter TargetName="ExpandPath" Property="Fill" Value="White" />
  36. </Trigger>
  37. </ControlTemplate.Triggers>
  38. </ControlTemplate>
  39. </Setter.Value>
  40. </Setter>
  41. </Style>
  42. <!-- 显示虚线样式TreeViewItem -->
  43. <Style x:Key="LineTreeViewItem" TargetType="{x:Type TreeViewItem}">
  44. <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
  45. <Setter Property="IsEnabled" Value="{Binding IsEnabled}" />
  46. <Setter Property="Background" Value="{DynamicResource TreeBackground}" />
  47. <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
  48. <Setter Property="Foreground" Value="{DynamicResource TreeForeground}" />
  49. <Setter Property="BorderBrush" Value="{DynamicResource CommonBorderBrush}" />
  50. <Setter Property="Template">
  51. <Setter.Value>
  52. <ControlTemplate TargetType="{x:Type TreeViewItem}">
  53. <!-- <ColumnDefinition Width="*" /> -->
  54. <Grid>
  55. <!--
  56. <Grid.ColumnDefinitions>
  57. <ColumnDefinition Width="Auto" MinWidth="19" />
  58. <ColumnDefinition Width="auto" />
  59. </Grid.ColumnDefinitions>
  60. <Grid.RowDefinitions>
  61. <RowDefinition Height="Auto" />
  62. <RowDefinition />
  63. </Grid.RowDefinitions>
  64. -->
  65. <StackPanel Orientation="Vertical">
  66. <StackPanel Orientation="Horizontal">
  67. <ToggleButton x:Name="Expander"
  68. VerticalAlignment="Center"
  69. BorderBrush="{TemplateBinding BorderBrush}"
  70. ClickMode="Press"
  71. IsChecked="{Binding IsExpanded,
  72. RelativeSource={RelativeSource TemplatedParent}}"
  73. Style="{StaticResource ExpandToggleButtonStyle}" />
  74. <Rectangle x:Name="VerLn"
  75. Grid.RowSpan="2"
  76. Width="1"
  77. Margin="10,0,0,0"
  78. SnapsToDevicePixels="true"
  79. Stretch="Fill"
  80. Stroke="{DynamicResource TreeForeground}"
  81. StrokeDashArray="1,3"
  82. StrokeThickness="1" />
  83. <Rectangle x:Name="HorLn"
  84. Width="20"
  85. Height="1"
  86. SnapsToDevicePixels="true"
  87. Stroke="{DynamicResource TreeForeground}"
  88. StrokeDashArray="1,3"
  89. StrokeThickness="1" />
  90. <Border x:Name="Bd"
  91. Grid.Column="1"
  92. Background="{TemplateBinding Background}"
  93. BorderBrush="{TemplateBinding BorderBrush}"
  94. BorderThickness="{TemplateBinding BorderThickness}"
  95. Padding="{TemplateBinding Padding}">
  96. <ContentPresenter x:Name="PART_Header"
  97. Margin="3"
  98. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  99. ContentSource="Header" />
  100. </Border>
  101. </StackPanel>
  102. <ItemsPresenter x:Name="ItemsHost"
  103. Grid.Row="1"
  104. Grid.Column="1"
  105. Grid.ColumnSpan="2" />
  106. </StackPanel>
  107. </Grid>
  108. <ControlTemplate.Triggers>
  109. <!-- 无父无子的项不显示线 -->
  110. <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource NewTreeViewLineConverter}}" Value="true">
  111. <Setter TargetName="HorLn" Property="Visibility" Value="Collapsed" />
  112. <Setter TargetName="VerLn" Property="Visibility" Value="Collapsed" />
  113. <Setter TargetName="Expander" Property="Visibility" Value="Collapsed" />
  114. <Setter TargetName="Bd" Property="Margin" Value="20,0" />
  115. </DataTrigger>
  116. <!-- 最后一项竖线的显示问题 -->
  117. <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TreeViewLineConverter}}" Value="true">
  118. <Setter TargetName="VerLn" Property="Height" Value="9" />
  119. <Setter TargetName="VerLn" Property="VerticalAlignment" Value="Top" />
  120. </DataTrigger>
  121. <Trigger Property="IsExpanded" Value="false">
  122. <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
  123. </Trigger>
  124. <Trigger Property="HasItems" Value="false">
  125. <Setter TargetName="Expander" Property="Visibility" Value="Collapsed" />
  126. </Trigger>
  127. <Trigger Property="HasItems" Value="true">
  128. <Setter TargetName="VerLn" Property="Visibility" Value="Collapsed" />
  129. <Setter TargetName="HorLn" Property="Visibility" Value="Collapsed" />
  130. </Trigger>
  131. <Trigger Property="IsSelected" Value="true">
  132. <Setter Property="Foreground" Value="{DynamicResource TreeItemSelectedForeground}" />
  133. </Trigger>
  134. <Trigger Property="IsMouseOver" Value="true">
  135. <Setter Property="Foreground" Value="{DynamicResource TreeMouseOverForeground}" />
  136. <Setter TargetName="Bd" Property="Background" Value="{DynamicResource ExpanderHeadBrush}" />
  137. </Trigger>
  138. <Trigger Property="IsEnabled" Value="False">
  139. <Setter Property="Foreground" Value="{DynamicResource DisEnableBrush}" />
  140. </Trigger>
  141. </ControlTemplate.Triggers>
  142. </ControlTemplate>
  143. </Setter.Value>
  144. </Setter>
  145. <Setter Property="ItemsPanel">
  146. <Setter.Value>
  147. <ItemsPanelTemplate>
  148. <StackPanel />
  149. </ItemsPanelTemplate>
  150. </Setter.Value>
  151. </Setter>
  152. </Style>
  153. </ResourceDictionary>