Advertisement
Guest User

Fixed TabControl.xaml

a guest
May 14th, 2016
1,408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.14 KB | None | 0 0
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:Behaviours="clr-namespace:MahApps.Metro.Behaviours" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:MahApps.Metro.Controls">
  2.  
  3. <ResourceDictionary.MergedDictionaries>
  4. <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Colors.xaml" />
  5. <ResourceDictionary>
  6.  
  7. <!-- General -->
  8. <SolidColorBrush x:Key="BackgroundHighlighted" Color="#54545C" />
  9. <SolidColorBrush x:Key="BorderBrushHighlighted" Color="#6A6A75" />
  10. <SolidColorBrush x:Key="BackgroundSelected" Color="#CCcb0000" />
  11. <SolidColorBrush x:Key="BorderBrushSelected" Color="#1C97EA" />
  12. <SolidColorBrush x:Key="BackgroundNormal" Color="#3F3F46" />
  13. <SolidColorBrush x:Key="BorderBrushNormal" Color="#54545C" />
  14.  
  15. <!-- Close Button -->
  16. <SolidColorBrush x:Key="CloseButtonBackgroundHighlighted" Color="#39ADFB" />
  17. <SolidColorBrush x:Key="CloseButtonBackgroundPressed" Color="#084E7D" />
  18. <SolidColorBrush x:Key="CloseButtonStroke" Color="#AAFFFFFF" />
  19. <SolidColorBrush x:Key="CloseButtonStrokeHighlighted" Color="#FFFFFF" />
  20.  
  21. </ResourceDictionary>
  22. </ResourceDictionary.MergedDictionaries>
  23.  
  24. <Style x:Key="StandardTabControl" TargetType="{x:Type TabControl}">
  25. <Style.Resources>
  26. <Style TargetType="{x:Type TabItem}">
  27. <Setter Property="Background" Value="Transparent" />
  28. <Setter Property="FocusVisualStyle" Value="{x:Null}" />
  29. <Setter Property="Foreground" Value="{StaticResource Foreground}" />
  30. <Setter Property="Template">
  31. <Setter.Value>
  32. <ControlTemplate TargetType="{x:Type TabItem}">
  33. <Grid Height="30"
  34. Background="{TemplateBinding Background}"
  35. SnapsToDevicePixels="true">
  36. <Grid.ColumnDefinitions>
  37. <ColumnDefinition Width="Auto" />
  38. <ColumnDefinition Width="25" />
  39. </Grid.ColumnDefinitions>
  40. <ContentPresenter Grid.Column="0"
  41. Margin="10 0 10 0"
  42. HorizontalAlignment="Center"
  43. VerticalAlignment="Center"
  44. ContentSource="Header" />
  45. <Button Grid.Column="1"
  46. Width="15"
  47. Height="15"
  48. HorizontalAlignment="Center"
  49. VerticalAlignment="Center"
  50. Command="{Binding Path=CloseCommand}"
  51. DockPanel.Dock="Right">
  52. <Button.Style>
  53. <Style TargetType="{x:Type Button}">
  54. <Setter Property="Background" Value="Transparent" />
  55. <Setter Property="Cursor" Value="Hand" />
  56. <Setter Property="Focusable" Value="False" />
  57. <Setter Property="Template">
  58. <Setter.Value>
  59. <ControlTemplate TargetType="{x:Type Button}">
  60. <Grid Background="{TemplateBinding Background}">
  61. <Path x:Name="ButtonPath"
  62. Margin="2"
  63. HorizontalAlignment="Center"
  64. VerticalAlignment="Center"
  65. Stroke="{DynamicResource CloseButtonStroke}"
  66. StrokeThickness="2"
  67. Data="M0,0 L1,1 M0,1 L1,0"
  68. Stretch="Uniform"
  69. StrokeEndLineCap="Flat"
  70. StrokeStartLineCap="Flat" />
  71. </Grid>
  72. <ControlTemplate.Triggers>
  73. <MultiDataTrigger>
  74. <MultiDataTrigger.Conditions>
  75. <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}" Value="false" />
  76. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}" Value="false" />
  77. </MultiDataTrigger.Conditions>
  78. <MultiDataTrigger.Setters>
  79. <Setter Property="Visibility" Value="Hidden" />
  80. </MultiDataTrigger.Setters>
  81. </MultiDataTrigger>
  82. <Trigger Property="IsEnabled" Value="False">
  83. <Setter Property="Visibility" Value="Hidden" />
  84. </Trigger>
  85. <Trigger Property="IsMouseOver" Value="True">
  86. <Setter Property="Background" Value="{DynamicResource CloseButtonBackgroundHighlighted}" />
  87. <Setter TargetName="ButtonPath" Property="Stroke" Value="{DynamicResource CloseButtonStrokeHighlighted}" />
  88. </Trigger>
  89. <Trigger Property="IsPressed" Value="true">
  90. <Setter Property="Background" Value="{DynamicResource CloseButtonBackgroundPressed}" />
  91. <Setter TargetName="ButtonPath" Property="Margin" Value="2.5 2.5 1.5 1.5" />
  92. <Setter TargetName="ButtonPath" Property="Stroke" Value="{DynamicResource CloseButtonStroke}" />
  93. </Trigger>
  94. </ControlTemplate.Triggers>
  95. </ControlTemplate>
  96. </Setter.Value>
  97. </Setter>
  98. </Style>
  99. </Button.Style>
  100. </Button>
  101. </Grid>
  102. <ControlTemplate.Triggers>
  103. <Trigger Property="IsSelected" Value="false">
  104. <Setter Property="Background" Value="Transparent" />
  105. </Trigger>
  106. <Trigger Property="IsMouseOver" Value="true">
  107. <Setter Property="Background" Value="{DynamicResource BorderBrushSelected}" />
  108. </Trigger>
  109. <Trigger Property="IsSelected" Value="true">
  110. <Setter Property="Background" Value="{DynamicResource BackgroundSelected}" />
  111. </Trigger>
  112. </ControlTemplate.Triggers>
  113. </ControlTemplate>
  114. </Setter.Value>
  115. </Setter>
  116. </Style>
  117. </Style.Resources>
  118.  
  119. <Setter Property="Controls:TabControlHelper.Transition" Value="Left" />
  120. <Setter Property="Template">
  121. <Setter.Value>
  122. <ControlTemplate TargetType="{x:Type TabControl}">
  123. <Grid ClipToBounds="{TemplateBinding ClipToBounds}"
  124. KeyboardNavigation.TabNavigation="Local"
  125. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
  126. <Grid.ColumnDefinitions>
  127. <ColumnDefinition x:Name="ColumnDefinition0" />
  128. <ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
  129. </Grid.ColumnDefinitions>
  130. <Grid.RowDefinitions>
  131. <RowDefinition x:Name="RowDefinition0" Height="Auto" />
  132. <RowDefinition x:Name="RowDefinition1" Height="*" />
  133. </Grid.RowDefinitions>
  134. <TabPanel x:Name="HeaderPanel"
  135. Grid.Row="0"
  136. Grid.Column="0"
  137. Panel.ZIndex="1"
  138. IsItemsHost="True"
  139. KeyboardNavigation.TabIndex="1" />
  140. <Border x:Name="ContentPanel"
  141. Grid.Row="1"
  142. Grid.Column="0"
  143. BorderBrush="{DynamicResource BackgroundSelected}"
  144. Background="{DynamicResource Background}"
  145. KeyboardNavigation.DirectionalNavigation="Contained"
  146. KeyboardNavigation.TabIndex="2"
  147. KeyboardNavigation.TabNavigation="Local">
  148. <Controls:TransitioningContentControl Behaviours:ReloadBehavior.OnSelectedTabChanged="True"
  149. RestartTransitionOnContentChange="True"
  150. Transition="{TemplateBinding Controls:TabControlHelper.Transition}">
  151. <ContentPresenter x:Name="PART_SelectedContentHost"
  152. Margin="{TemplateBinding Padding}"
  153. ContentSource="SelectedContent"
  154. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  155. </Controls:TransitioningContentControl>
  156. </Border>
  157. </Grid>
  158. <ControlTemplate.Triggers>
  159. <Trigger Property="TabStripPlacement" Value="Bottom">
  160. <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
  161. <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="1" />
  162. <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
  163. <Setter TargetName="RowDefinition1" Property="Height" Value="Auto" />
  164. </Trigger>
  165. <Trigger Property="TabStripPlacement" Value="Left">
  166. <Setter Property="Controls:TabControlHelper.Transition" Value="Right" />
  167. <Setter TargetName="ColumnDefinition0" Property="Width" Value="Auto" />
  168. <Setter TargetName="ColumnDefinition1" Property="Width" Value="*" />
  169. <Setter TargetName="ContentPanel" Property="Grid.Column" Value="1" />
  170. <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
  171. <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="0" />
  172. <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0" />
  173. <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
  174. <Setter TargetName="RowDefinition1" Property="Height" Value="0" />
  175. </Trigger>
  176. <Trigger Property="TabStripPlacement" Value="Right">
  177. <Setter TargetName="ColumnDefinition0" Property="Width" Value="*" />
  178. <Setter TargetName="ColumnDefinition1" Property="Width" Value="Auto" />
  179. <Setter TargetName="ContentPanel" Property="Grid.Column" Value="0" />
  180. <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
  181. <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="1" />
  182. <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0" />
  183. <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
  184. <Setter TargetName="RowDefinition1" Property="Height" Value="0" />
  185. </Trigger>
  186. <Trigger Property="IsEnabled" Value="False">
  187. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
  188. </Trigger>
  189. </ControlTemplate.Triggers>
  190. </ControlTemplate>
  191. </Setter.Value>
  192. </Setter>
  193. </Style>
  194.  
  195. <DataTemplate x:Key="ClosableTabItemTemplate">
  196. <DockPanel>
  197. <ContentPresenter VerticalAlignment="Center" Content="{Binding DisplayName}">
  198. <ContentPresenter.Resources>
  199. <Style TargetType="TextBlock">
  200. <Setter Property="FontSize" Value="20" />
  201. <Setter Property="Foreground" Value="{StaticResource Foreground}" />
  202. </Style>
  203. </ContentPresenter.Resources>
  204. </ContentPresenter>
  205. </DockPanel>
  206. </DataTemplate>
  207.  
  208. <!-- This template explains how to render the 'Workspace' content area in the main window. -->
  209. <DataTemplate x:Key="WorkspacesTemplate">
  210. <TabControl Margin="0"
  211. Style="{DynamicResource StandardTabControl}"
  212. IsSynchronizedWithCurrentItem="True"
  213. ItemTemplate="{StaticResource ClosableTabItemTemplate}"
  214. ItemsSource="{Binding}" />
  215. </DataTemplate>
  216.  
  217. </ResourceDictionary>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement