ToolBarBaseStyle.xaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:hc="clr-namespace:HandyControl.Controls">
  2. <Style x:Key="{x:Static ToolBar.SeparatorStyleKey}" TargetType="Separator">
  3. <Setter Property="Background" Value="{DynamicResource BorderBrush}" />
  4. <Setter Property="Width" Value="1" />
  5. </Style>
  6. <!--Styles for controls in a toolbar.-->
  7. <Style x:Key="ToolBarTrayBaseStyle" TargetType="ToolBarTray">
  8. <Setter Property="Background" Value="Transparent" />
  9. </Style>
  10. <Style x:Key="{x:Static ToolBar.ButtonStyleKey}" BasedOn="{StaticResource ButtonBaseStyle}" TargetType="Button">
  11. <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
  12. <Setter Property="BorderThickness" Value="1" />
  13. <Style.Triggers>
  14. <Trigger Property="IsMouseOver" Value="True">
  15. <Setter Property="Background" Value="{DynamicResource DarkDefaultBrush}" />
  16. </Trigger>
  17. <Trigger Property="IsPressed" Value="True">
  18. <Setter Property="Background" Value="{DynamicResource BorderBrush}" />
  19. </Trigger>
  20. </Style.Triggers>
  21. </Style>
  22. <Style x:Key="{x:Static ToolBar.CheckBoxStyleKey}" BasedOn="{StaticResource CheckBoxBaseStyle}" TargetType="CheckBox" />
  23. <Style x:Key="{x:Static ToolBar.RadioButtonStyleKey}" BasedOn="{StaticResource RadioButtonBaseStyle}" TargetType="RadioButton" />
  24. <Style x:Key="{x:Static ToolBar.ComboBoxStyleKey}" BasedOn="{StaticResource ComboBoxBaseStyle}" TargetType="ComboBox" />
  25. <Style x:Key="{x:Static ToolBar.TextBoxStyleKey}" BasedOn="{StaticResource TextBoxBaseStyle}" TargetType="TextBox" />
  26. <Style x:Key="{x:Static ToolBar.MenuStyleKey}" BasedOn="{StaticResource MenuBaseStyle}" TargetType="Menu" />
  27. <Style x:Key="{x:Static ToolBar.ToggleButtonStyleKey}" BasedOn="{StaticResource ToggleButtonBaseStyle}" TargetType="ToggleButton">
  28. <Setter Property="Background" Value="{DynamicResource RegionBrush}" />
  29. <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
  30. <Setter Property="BorderThickness" Value="1" />
  31. <Style.Triggers>
  32. <Trigger Property="IsMouseOver" Value="True">
  33. <Setter Property="Background" Value="{DynamicResource DarkDefaultBrush}" />
  34. </Trigger>
  35. <Trigger Property="IsPressed" Value="True">
  36. <Setter Property="Background" Value="{DynamicResource BorderBrush}" />
  37. </Trigger>
  38. </Style.Triggers>
  39. </Style>
  40. <Style x:Key="ToolBarThumbHorizontalStyle" TargetType="Thumb">
  41. <Setter Property="Template">
  42. <Setter.Value>
  43. <ControlTemplate TargetType="Thumb">
  44. <Border SnapsToDevicePixels="True" Padding="{TemplateBinding Padding}" Background="Transparent">
  45. <Path Stretch="Uniform" Width="4" Fill="{DynamicResource PrimaryBrush}" Data="{StaticResource DragVerticalGeometry}" SnapsToDevicePixels="True" />
  46. </Border>
  47. <ControlTemplate.Triggers>
  48. <Trigger Property="IsMouseOver" Value="true">
  49. <Setter Property="Cursor" Value="SizeAll" />
  50. </Trigger>
  51. </ControlTemplate.Triggers>
  52. </ControlTemplate>
  53. </Setter.Value>
  54. </Setter>
  55. </Style>
  56. <Style x:Key="ToolBarThumbVerticalStyle" TargetType="Thumb">
  57. <Setter Property="Template">
  58. <Setter.Value>
  59. <ControlTemplate TargetType="Thumb">
  60. <Border SnapsToDevicePixels="True" Padding="{TemplateBinding Padding}" Background="Transparent">
  61. <Path Stretch="Uniform" Height="4" Fill="{DynamicResource PrimaryBrush}" Data="{StaticResource DragHorizontalGeometry}" SnapsToDevicePixels="True" />
  62. </Border>
  63. <ControlTemplate.Triggers>
  64. <Trigger Property="IsMouseOver" Value="true">
  65. <Setter Property="Cursor" Value="SizeAll" />
  66. </Trigger>
  67. </ControlTemplate.Triggers>
  68. </ControlTemplate>
  69. </Setter.Value>
  70. </Setter>
  71. </Style>
  72. <Style x:Key="ToolBarOverflowButtonStyle" BasedOn="{StaticResource ToggleButtonIcon}" TargetType="ToggleButton">
  73. <Setter Property="Background" Value="Transparent" />
  74. <Setter Property="BorderThickness" Value="0" />
  75. <Setter Property="MinHeight" Value="0" />
  76. <Setter Property="MinWidth" Value="0" />
  77. <Setter Property="Height" Value="Auto" />
  78. <Setter Property="Width" Value="Auto" />
  79. <Setter Property="ClickMode" Value="Press" />
  80. <Style.Triggers>
  81. <Trigger Property="IsMouseOver" Value="True">
  82. <Setter Property="Background" Value="{DynamicResource BorderBrush}" />
  83. </Trigger>
  84. </Style.Triggers>
  85. </Style>
  86. <ControlTemplate x:Key="ToolBarVerticalTemplate" TargetType="ToolBar">
  87. <Border x:Name="MainPanelBorder" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
  88. <Grid SnapsToDevicePixels="true">
  89. <Grid.RowDefinitions>
  90. <RowDefinition />
  91. <RowDefinition Height="Auto" />
  92. </Grid.RowDefinitions>
  93. <DockPanel KeyboardNavigation.TabIndex="1" KeyboardNavigation.TabNavigation="Local">
  94. <Thumb x:Name="ToolBarThumb" DockPanel.Dock="Top" Style="{StaticResource ToolBarThumbVerticalStyle}" Height="10" Margin="0 4 0 0" />
  95. <ContentPresenter x:Name="ToolBarHeader" DockPanel.Dock="Top" ContentSource="Header" HorizontalAlignment="Center" Margin="4 4 4 0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" />
  96. <ToolBarPanel x:Name="PART_ToolBarPanel" IsItemsHost="true" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}" />
  97. </DockPanel>
  98. <ToggleButton x:Name="ButtonOverflow" Margin="2 0 2 2" Padding="6 4" HorizontalContentAlignment="Right" hc:IconElement.Height="8" hc:IconSwitchElement.GeometrySelected="{StaticResource LeftGeometry}" hc:IconElement.Geometry="{StaticResource RightGeometry}" Style="{StaticResource ToolBarOverflowButtonStyle}" Grid.Row="1" IsChecked="{Binding IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" IsEnabled="{TemplateBinding HasOverflowItems}" />
  99. <Popup PlacementTarget="{Binding ElementName=ButtonOverflow}" AllowsTransparency="true" Focusable="false" IsOpen="{Binding IsOverflowOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Right" StaysOpen="false">
  100. <Border CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Background="{DynamicResource RegionBrush}" RenderOptions.ClearTypeHint="Enabled">
  101. <ToolBarOverflowPanel x:Name="PART_ToolBarOverflowPanel" KeyboardNavigation.DirectionalNavigation="Cycle" FocusVisualStyle="{x:Null}" Focusable="true" Margin="6" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle" WrapWidth="200" />
  102. </Border>
  103. </Popup>
  104. </Grid>
  105. </Border>
  106. <ControlTemplate.Triggers>
  107. <Trigger Property="IsOverflowOpen" Value="true">
  108. <Setter Property="IsEnabled" TargetName="ToolBarThumb" Value="false" />
  109. </Trigger>
  110. <Trigger Property="Header" Value="{x:Null}">
  111. <Setter Property="Visibility" TargetName="ToolBarHeader" Value="Collapsed" />
  112. </Trigger>
  113. <Trigger Property="ToolBarTray.IsLocked" Value="true">
  114. <Setter Property="Visibility" TargetName="ToolBarThumb" Value="Collapsed" />
  115. </Trigger>
  116. </ControlTemplate.Triggers>
  117. </ControlTemplate>
  118. <ControlTemplate x:Key="ToolBarHorizontalTemplate" TargetType="ToolBar">
  119. <Border x:Name="MainPanelBorder" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
  120. <Grid SnapsToDevicePixels="true">
  121. <Grid.ColumnDefinitions>
  122. <ColumnDefinition />
  123. <ColumnDefinition Width="Auto" />
  124. </Grid.ColumnDefinitions>
  125. <DockPanel KeyboardNavigation.TabIndex="1" KeyboardNavigation.TabNavigation="Local">
  126. <Thumb x:Name="ToolBarThumb" Style="{StaticResource ToolBarThumbHorizontalStyle}" Width="10" Margin="4 0 0 0" />
  127. <ContentPresenter x:Name="ToolBarHeader" ContentSource="Header" HorizontalAlignment="Center" Margin="4 4 0 4" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" />
  128. <ToolBarPanel x:Name="PART_ToolBarPanel" IsItemsHost="true" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}" />
  129. </DockPanel>
  130. <ToggleButton x:Name="ButtonOverflow" Margin="0 2 2 2" Padding="4 6" VerticalContentAlignment="Bottom" hc:IconElement.Width="8" hc:IconSwitchElement.GeometrySelected="{StaticResource UpGeometry}" hc:IconElement.Geometry="{StaticResource DownGeometry}" Style="{StaticResource ToolBarOverflowButtonStyle}" Grid.Column="1" IsChecked="{Binding IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" IsEnabled="{TemplateBinding HasOverflowItems}" />
  131. <Popup PlacementTarget="{Binding ElementName=ButtonOverflow}" AllowsTransparency="true" Focusable="false" IsOpen="{Binding IsOverflowOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom" StaysOpen="false">
  132. <Border CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Background="{DynamicResource RegionBrush}" RenderOptions.ClearTypeHint="Enabled">
  133. <ToolBarOverflowPanel x:Name="PART_ToolBarOverflowPanel" KeyboardNavigation.DirectionalNavigation="Cycle" FocusVisualStyle="{x:Null}" Focusable="true" Margin="6" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle" WrapWidth="200" />
  134. </Border>
  135. </Popup>
  136. </Grid>
  137. </Border>
  138. <ControlTemplate.Triggers>
  139. <Trigger Property="IsOverflowOpen" Value="true">
  140. <Setter Property="IsEnabled" TargetName="ToolBarThumb" Value="false" />
  141. </Trigger>
  142. <Trigger Property="Header" Value="{x:Null}">
  143. <Setter Property="Visibility" TargetName="ToolBarHeader" Value="Collapsed" />
  144. </Trigger>
  145. <Trigger Property="ToolBarTray.IsLocked" Value="true">
  146. <Setter Property="Visibility" TargetName="ToolBarThumb" Value="Collapsed" />
  147. </Trigger>
  148. </ControlTemplate.Triggers>
  149. </ControlTemplate>
  150. <Style x:Key="ToolBarBaseStyle" TargetType="ToolBar">
  151. <Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}" />
  152. <Setter Property="Padding" Value="4" />
  153. <Setter Property="hc:BorderElement.CornerRadius" Value="{StaticResource DefaultCornerRadius}" />
  154. <Setter Property="Template" Value="{StaticResource ToolBarHorizontalTemplate}" />
  155. <Style.Triggers>
  156. <Trigger Property="Orientation" Value="Vertical">
  157. <Setter Property="Template" Value="{StaticResource ToolBarVerticalTemplate}" />
  158. </Trigger>
  159. </Style.Triggers>
  160. </Style>
  161. </ResourceDictionary>