TabControlStyle.xaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:cus="clr-namespace:PDF_Office.CustomControl">
  5. <Style x:Key="TabControlWithUnderLineStyle" TargetType="{x:Type TabControl}">
  6. <Setter Property="Padding" Value="2" />
  7. <Setter Property="HorizontalContentAlignment" Value="Center" />
  8. <Setter Property="VerticalContentAlignment" Value="Center" />
  9. <Setter Property="Background" Value="Transparent" />
  10. <Setter Property="BorderBrush" Value="#FFACACAC" />
  11. <Setter Property="BorderThickness" Value="0,0,0,1" />
  12. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
  13. <Setter Property="Template">
  14. <Setter.Value>
  15. <ControlTemplate TargetType="{x:Type TabControl}">
  16. <Grid
  17. x:Name="templateRoot"
  18. ClipToBounds="True"
  19. KeyboardNavigation.TabNavigation="Local"
  20. SnapsToDevicePixels="True">
  21. <Grid.ColumnDefinitions>
  22. <ColumnDefinition x:Name="ColumnDefinition0" />
  23. <ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
  24. </Grid.ColumnDefinitions>
  25. <Grid.RowDefinitions>
  26. <RowDefinition x:Name="RowDefinition0" Height="Auto" />
  27. <RowDefinition x:Name="RowDefinition1" Height="*" />
  28. </Grid.RowDefinitions>
  29. <!-- 加滑轨配合滑轨样式可实现箭头左右滚动的菜单栏 -->
  30. <!--<ScrollViewer Margin="140 0 140 0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">-->
  31. <TabPanel
  32. x:Name="HeaderPanel"
  33. Grid.Row="0"
  34. Grid.Column="0"
  35. HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
  36. VerticalAlignment="{TemplateBinding VerticalAlignment}"
  37. Panel.ZIndex="1"
  38. Background="Transparent"
  39. IsItemsHost="True"
  40. KeyboardNavigation.TabIndex="1" />
  41. <!--</ScrollViewer>-->
  42. <!-- 页头和中间内容的分割线 -->
  43. <Line
  44. Margin="0,0,0,1"
  45. VerticalAlignment="Bottom"
  46. SnapsToDevicePixels="True"
  47. Stroke="#E7E9EC"
  48. StrokeThickness="0"
  49. X1="0"
  50. X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" />
  51. <Border
  52. x:Name="ContentPanel"
  53. Grid.Row="1"
  54. Grid.Column="0"
  55. Background="{TemplateBinding Background}"
  56. BorderBrush="{TemplateBinding BorderBrush}"
  57. BorderThickness="{TemplateBinding BorderThickness}"
  58. KeyboardNavigation.DirectionalNavigation="Contained"
  59. KeyboardNavigation.TabIndex="2"
  60. KeyboardNavigation.TabNavigation="Local">
  61. <ContentPresenter
  62. x:Name="PART_SelectedContentHost"
  63. Margin="0"
  64. VerticalAlignment="Stretch"
  65. Content="{TemplateBinding SelectedContent}"
  66. ContentSource="SelectedContent"
  67. ContentStringFormat="{TemplateBinding SelectedContentStringFormat}"
  68. ContentTemplate="{TemplateBinding SelectedContentTemplate}"
  69. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  70. </Border>
  71. </Grid>
  72. <ControlTemplate.Triggers>
  73. <Trigger Property="TabStripPlacement" Value="Bottom">
  74. <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="1" />
  75. <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
  76. <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
  77. <Setter TargetName="RowDefinition1" Property="Height" Value="Auto" />
  78. </Trigger>
  79. <Trigger Property="TabStripPlacement" Value="Left">
  80. <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0" />
  81. <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
  82. <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="0" />
  83. <Setter TargetName="ContentPanel" Property="Grid.Column" Value="1" />
  84. <Setter TargetName="ColumnDefinition0" Property="Width" Value="Auto" />
  85. <Setter TargetName="ColumnDefinition1" Property="Width" Value="*" />
  86. <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
  87. <Setter TargetName="RowDefinition1" Property="Height" Value="0" />
  88. <Setter TargetName="HeaderPanel" Property="VerticalAlignment" Value="Top" />
  89. </Trigger>
  90. <Trigger Property="TabStripPlacement" Value="Right">
  91. <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0" />
  92. <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
  93. <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="1" />
  94. <Setter TargetName="ContentPanel" Property="Grid.Column" Value="0" />
  95. <Setter TargetName="ColumnDefinition0" Property="Width" Value="*" />
  96. <Setter TargetName="ColumnDefinition1" Property="Width" Value="Auto" />
  97. <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
  98. <Setter TargetName="RowDefinition1" Property="Height" Value="0" />
  99. </Trigger>
  100. <Trigger Property="IsEnabled" Value="False">
  101. <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
  102. </Trigger>
  103. </ControlTemplate.Triggers>
  104. </ControlTemplate>
  105. </Setter.Value>
  106. </Setter>
  107. <Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Cycle" />
  108. <Setter Property="KeyboardNavigation.TabNavigation" Value="Cycle" />
  109. </Style>
  110. <Style x:Key="TabItem_WithUnderLineStyle" TargetType="{x:Type cus:IconAndTextTabItem}">
  111. <Setter Property="Foreground" Value="Black" />
  112. <Setter Property="Background" Value="White" />
  113. <Setter Property="BorderBrush" Value="#FFACACAC" />
  114. <Setter Property="HorizontalContentAlignment" Value="Stretch" />
  115. <Setter Property="VerticalContentAlignment" Value="Stretch" />
  116. <Setter Property="AllowDrop" Value="True" />
  117. <Setter Property="SelectedForeground" Value="Black" />
  118. <Setter Property="FontSize" Value="14" />
  119. <Setter Property="Height" Value="40" />
  120. <Setter Property="Template">
  121. <Setter.Value>
  122. <ControlTemplate TargetType="{x:Type cus:IconAndTextTabItem}">
  123. <Grid
  124. x:Name="templateRoot"
  125. Margin="{TemplateBinding Padding}"
  126. Background="Transparent"
  127. SnapsToDevicePixels="True">
  128. <Border
  129. x:Name="_underline"
  130. HorizontalAlignment="Stretch"
  131. BorderBrush="#FF477EDE"
  132. BorderThickness="0" />
  133. <StackPanel Orientation="Horizontal">
  134. <Path
  135. x:Name="NormalPathIcon"
  136. MaxWidth="20"
  137. MaxHeight="20"
  138. Margin="0,0,4,0"
  139. Data="{Binding NormalPathIcon, RelativeSource={RelativeSource Mode=TemplatedParent}}"
  140. Fill="Black"
  141. Visibility="Visible" />
  142. <Image
  143. x:Name="SelectedIcon"
  144. MaxWidth="20"
  145. MaxHeight=" 20"
  146. Margin="0,0,4,0"
  147. Source="{Binding SelectedIcon, RelativeSource={RelativeSource Mode=TemplatedParent}}"
  148. Visibility="Collapsed" />
  149. <TextBlock
  150. x:Name="txt"
  151. Margin="0,0,4,0"
  152. HorizontalAlignment="Center"
  153. VerticalAlignment="Center"
  154. Foreground="{TemplateBinding Foreground}"
  155. Text="{TemplateBinding Header}"
  156. TextTrimming="CharacterEllipsis"
  157. ToolTip="{TemplateBinding Header}"
  158. Visibility="Visible" />
  159. </StackPanel>
  160. </Grid>
  161. <ControlTemplate.Triggers>
  162. <MultiDataTrigger>
  163. <MultiDataTrigger.Conditions>
  164. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
  165. <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top" />
  166. </MultiDataTrigger.Conditions>
  167. <Setter TargetName="SelectedIcon" Property="Visibility" Value="Collapsed" />
  168. <Setter TargetName="NormalPathIcon" Property="Visibility" Value="Visible" />
  169. <Setter TargetName="txt" Property="Foreground" Value="#FF000000" />
  170. </MultiDataTrigger>
  171. <MultiDataTrigger>
  172. <MultiDataTrigger.Conditions>
  173. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" />
  174. <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Left" />
  175. </MultiDataTrigger.Conditions>
  176. <Setter TargetName="templateRoot" Property="Opacity" Value="0.56" />
  177. </MultiDataTrigger>
  178. <MultiDataTrigger>
  179. <MultiDataTrigger.Conditions>
  180. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" />
  181. <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Bottom" />
  182. </MultiDataTrigger.Conditions>
  183. <Setter TargetName="templateRoot" Property="Opacity" Value="0.56" />
  184. </MultiDataTrigger>
  185. <MultiDataTrigger>
  186. <MultiDataTrigger.Conditions>
  187. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" />
  188. <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Right" />
  189. </MultiDataTrigger.Conditions>
  190. <Setter TargetName="templateRoot" Property="Opacity" Value="0.56" />
  191. </MultiDataTrigger>
  192. <MultiDataTrigger>
  193. <MultiDataTrigger.Conditions>
  194. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" />
  195. <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top" />
  196. </MultiDataTrigger.Conditions>
  197. <Setter TargetName="templateRoot" Property="Opacity" Value="0.56" />
  198. </MultiDataTrigger>
  199. <MultiDataTrigger>
  200. <MultiDataTrigger.Conditions>
  201. <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="false" />
  202. <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top" />
  203. </MultiDataTrigger.Conditions>
  204. <Setter TargetName="NormalPathIcon" Property="Opacity" Value="0.56" />
  205. </MultiDataTrigger>
  206. <MultiDataTrigger>
  207. <MultiDataTrigger.Conditions>
  208. <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true" />
  209. <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top" />
  210. </MultiDataTrigger.Conditions>
  211. <Setter Property="Panel.ZIndex" Value="1" />
  212. <Setter TargetName="txt" Property="Foreground" Value="{Binding SelectedForeground, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
  213. <Setter TargetName="_underline" Property="BorderThickness" Value="0,0,0,2" />
  214. <Setter TargetName="SelectedIcon" Property="Visibility" Value="Collapsed" />
  215. <Setter TargetName="NormalPathIcon" Property="Visibility" Value="Visible" />
  216. </MultiDataTrigger>
  217. </ControlTemplate.Triggers>
  218. </ControlTemplate>
  219. </Setter.Value>
  220. </Setter>
  221. </Style>
  222. </ResourceDictionary>