ToggleButtonBaseStyle.xaml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:hc="clr-namespace:HandyControl.Controls"
  4. xmlns:system="clr-namespace:System;assembly=mscorlib">
  5. <Style x:Key="ToggleButtonBaseStyle" BasedOn="{StaticResource ButtonBaseBaseStyle}" TargetType="ToggleButton">
  6. <Setter Property="BorderThickness" Value="1"/>
  7. <Setter Property="hc:BorderElement.CornerRadius" Value="{StaticResource DefaultCornerRadius}"/>
  8. <Setter Property="Template">
  9. <Setter.Value>
  10. <ControlTemplate TargetType="ToggleButton">
  11. <hc:SimplePanel>
  12. <Border Background="{TemplateBinding Background}" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}"/>
  13. <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}">
  14. <StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}">
  15. <Path x:Name="PathMain" Width="{TemplateBinding hc:IconElement.Width}" Height="{TemplateBinding hc:IconElement.Height}" Fill="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Stretch="Uniform" Data="{TemplateBinding hc:IconElement.Geometry}"/>
  16. <ContentPresenter x:Name="ContentPresenterMain" RecognizesAccessKey="True" VerticalAlignment="Center" Margin="6,0,0,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
  17. </StackPanel>
  18. </Border>
  19. <Border Margin="-1" Visibility="Collapsed" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" x:Name="BorderChecked" BorderThickness="4" BorderBrush="{DynamicResource DarkMaskBrush}"/>
  20. </hc:SimplePanel>
  21. <ControlTemplate.Triggers>
  22. <Trigger Property="IsChecked" Value="true">
  23. <Setter TargetName="BorderChecked" Property="Visibility" Value="Visible"/>
  24. </Trigger>
  25. <Trigger Property="Content" Value="{x:Null}">
  26. <Setter Property="Visibility" Value="Collapsed" TargetName="ContentPresenterMain"/>
  27. </Trigger>
  28. <Trigger Property="hc:IconElement.Geometry" Value="{x:Null}">
  29. <Setter Property="Visibility" Value="Collapsed" TargetName="PathMain"/>
  30. <Setter Property="Margin" Value="0" TargetName="ContentPresenterMain"/>
  31. </Trigger>
  32. </ControlTemplate.Triggers>
  33. </ControlTemplate>
  34. </Setter.Value>
  35. </Setter>
  36. <Style.Triggers>
  37. <Trigger Property="IsMouseOver" Value="True">
  38. <Setter Property="Opacity" Value=".9"/>
  39. </Trigger>
  40. <Trigger Property="IsPressed" Value="True">
  41. <Setter Property="Opacity" Value=".6"/>
  42. </Trigger>
  43. <Trigger Property="IsEnabled" Value="False">
  44. <Setter Property="Opacity" Value="0.4"/>
  45. </Trigger>
  46. </Style.Triggers>
  47. </Style>
  48. <Style x:Key="ToggleButtonIconBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="ToggleButton">
  49. <Setter Property="Foreground" Value="{DynamicResource TextIconBrush}"/>
  50. <Setter Property="Width" Value="{StaticResource DefaultControlHeight}"/>
  51. <Setter Property="Height" Value="{StaticResource DefaultControlHeight}"/>
  52. <Setter Property="Padding" Value="8"/>
  53. <Setter Property="hc:IconSwitchElement.Geometry" Value="{x:Null}"/>
  54. <Setter Property="hc:IconSwitchElement.GeometrySelected" Value="{x:Null}"/>
  55. <Setter Property="hc:BorderElement.CornerRadius" Value="{StaticResource DefaultCornerRadius}"/>
  56. <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
  57. <Setter Property="BorderThickness" Value="1"/>
  58. <Setter Property="Template">
  59. <Setter.Value>
  60. <ControlTemplate TargetType="ToggleButton">
  61. <hc:SimplePanel>
  62. <Border Background="{TemplateBinding Background}" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}"/>
  63. <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}">
  64. <ContentControl HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
  65. <Path x:Name="PathIcon" Width="{TemplateBinding hc:IconElement.Width}" Height="{TemplateBinding hc:IconElement.Height}" Fill="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Stretch="Uniform" Data="{TemplateBinding hc:IconSwitchElement.Geometry}"/>
  66. </ContentControl>
  67. </Border>
  68. <Border Visibility="Collapsed" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" x:Name="BorderChecked" BorderThickness="4" BorderBrush="{TemplateBinding BorderBrush}"/>
  69. </hc:SimplePanel>
  70. <ControlTemplate.Triggers>
  71. <Trigger Property="IsChecked" Value="True">
  72. <Setter TargetName="PathIcon" Property="Data" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(hc:IconSwitchElement.GeometrySelected)}"/>
  73. </Trigger>
  74. </ControlTemplate.Triggers>
  75. </ControlTemplate>
  76. </Setter.Value>
  77. </Setter>
  78. <Style.Triggers>
  79. <Trigger Property="IsMouseOver" Value="True">
  80. <Setter Property="Opacity" Value=".9"/>
  81. </Trigger>
  82. <Trigger Property="IsPressed" Value="True">
  83. <Setter Property="Opacity" Value=".6"/>
  84. </Trigger>
  85. <Trigger Property="IsEnabled" Value="False">
  86. <Setter Property="Opacity" Value="0.4"/>
  87. </Trigger>
  88. </Style.Triggers>
  89. </Style>
  90. <Style x:Key="ToggleButtonSwitchBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="ToggleButton">
  91. <Setter Property="FocusVisualStyle">
  92. <Setter.Value>
  93. <Style>
  94. <Setter Property="Control.Template">
  95. <Setter.Value>
  96. <ControlTemplate>
  97. <Rectangle Style="{StaticResource RectangleFocusVisualCircular}"/>
  98. </ControlTemplate>
  99. </Setter.Value>
  100. </Setter>
  101. </Style>
  102. </Setter.Value>
  103. </Setter>
  104. <Setter Property="hc:VisualElement.HighlightBrush" Value="{DynamicResource PrimaryBrush}" />
  105. <Setter Property="hc:VisualElement.HighlightForeground" Value="{DynamicResource SecondaryBorderBrush}" />
  106. <Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
  107. <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
  108. <Setter Property="BorderThickness" Value="0"/>
  109. <Setter Property="VerticalContentAlignment" Value="Center"/>
  110. <Setter Property="Padding" Value="6,0,0,0" />
  111. <Setter Property="Height" Value="24"/>
  112. <Setter Property="Template">
  113. <Setter.Value>
  114. <ControlTemplate TargetType="ToggleButton">
  115. <ControlTemplate.Resources>
  116. <Storyboard x:Key="StoryboardChecked">
  117. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)" Storyboard.TargetName="thumb">
  118. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="32">
  119. <EasingDoubleKeyFrame.EasingFunction>
  120. <CubicEase EasingMode="EaseInOut"/>
  121. </EasingDoubleKeyFrame.EasingFunction>
  122. </EasingDoubleKeyFrame>
  123. </DoubleAnimationUsingKeyFrames>
  124. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="lightBorder">
  125. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1" />
  126. </DoubleAnimationUsingKeyFrames>
  127. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="innerBorder">
  128. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0" />
  129. </DoubleAnimationUsingKeyFrames>
  130. </Storyboard>
  131. <Storyboard x:Key="StoryboardUnChecked">
  132. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)" Storyboard.TargetName="thumb">
  133. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0">
  134. <EasingDoubleKeyFrame.EasingFunction>
  135. <CubicEase EasingMode="EaseInOut" />
  136. </EasingDoubleKeyFrame.EasingFunction>
  137. </EasingDoubleKeyFrame>
  138. </DoubleAnimationUsingKeyFrames>
  139. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="lightBorder">
  140. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0" />
  141. </DoubleAnimationUsingKeyFrames>
  142. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="innerBorder">
  143. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1" />
  144. </DoubleAnimationUsingKeyFrames>
  145. </Storyboard>
  146. </ControlTemplate.Resources>
  147. <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
  148. <Grid.ColumnDefinitions>
  149. <ColumnDefinition Width="Auto" />
  150. <ColumnDefinition />
  151. </Grid.ColumnDefinitions>
  152. <Viewbox>
  153. <hc:SimplePanel Width="80" Height="48">
  154. <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="24" Name="innerBorder">
  155. <hc:ToggleBlock HorizontalAlignment="Right" Margin="0 0 12 0" IsChecked="{Binding Path=(hc:ToggleButtonAttach.ShowLabel),RelativeSource={RelativeSource TemplatedParent}}">
  156. <hc:ToggleBlock.CheckedContent>
  157. <Ellipse Width="16" Height="16" StrokeThickness="2" Stroke="{Binding Path=(hc:VisualElement.HighlightForeground),RelativeSource={RelativeSource TemplatedParent}}" />
  158. </hc:ToggleBlock.CheckedContent>
  159. </hc:ToggleBlock>
  160. </Border>
  161. <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Opacity="0" x:Name="lightBorder" Background="{Binding Path=(hc:VisualElement.HighlightBrush),RelativeSource={RelativeSource TemplatedParent}}" CornerRadius="24">
  162. <hc:ToggleBlock HorizontalAlignment="Left" Margin="18 0 0 0" IsChecked="{Binding Path=(hc:ToggleButtonAttach.ShowLabel),RelativeSource={RelativeSource TemplatedParent}}">
  163. <hc:ToggleBlock.CheckedContent>
  164. <Rectangle Width="3" Height="16" RadiusX="1.5" RadiusY="1.5" Fill="{DynamicResource TextIconBrush}" />
  165. </hc:ToggleBlock.CheckedContent>
  166. </hc:ToggleBlock>
  167. </Border>
  168. <Border Margin="2" HorizontalAlignment="Left" CornerRadius="22" Name="thumb" Effect="{StaticResource EffectShadow2}" Background="White" Width="44" Height="44" RenderTransformOrigin="0.5,0.5">
  169. <Border.RenderTransform>
  170. <TransformGroup>
  171. <TranslateTransform />
  172. </TransformGroup>
  173. </Border.RenderTransform>
  174. </Border>
  175. </hc:SimplePanel>
  176. </Viewbox>
  177. <ContentPresenter x:Name="contentPresenter" Visibility="Collapsed" Grid.Column="1" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
  178. </Grid>
  179. <ControlTemplate.Triggers>
  180. <Trigger Property="HasContent" Value="true">
  181. <Setter Property="Visibility" TargetName="contentPresenter" Value="Visible"/>
  182. </Trigger>
  183. <Trigger Property="IsChecked" Value="true">
  184. <Trigger.EnterActions>
  185. <BeginStoryboard Storyboard="{StaticResource StoryboardChecked}"/>
  186. </Trigger.EnterActions>
  187. <Trigger.ExitActions>
  188. <BeginStoryboard Storyboard="{StaticResource StoryboardUnChecked}"/>
  189. </Trigger.ExitActions>
  190. </Trigger>
  191. <Trigger Property="IsEnabled" Value="False">
  192. <Setter Property="Opacity" Value="0.4"/>
  193. </Trigger>
  194. </ControlTemplate.Triggers>
  195. </ControlTemplate>
  196. </Setter.Value>
  197. </Setter>
  198. </Style>
  199. <Style x:Key="ToggleButtonGroupItemBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="ToggleButton">
  200. <Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
  201. <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
  202. <Setter Property="BorderThickness" Value="1"/>
  203. <Setter Property="VerticalAlignment" Value="Center"/>
  204. <Setter Property="VerticalContentAlignment" Value="Center"/>
  205. <Setter Property="HorizontalContentAlignment" Value="Center"/>
  206. <Setter Property="hc:BorderElement.CornerRadius" Value="0"/>
  207. <Setter Property="Height" Value="{StaticResource DefaultControlHeight}"/>
  208. <Setter Property="Padding" Value="10,0"/>
  209. <Setter Property="Margin" Value="-1,0,0,0"/>
  210. <Setter Property="Template">
  211. <Setter.Value>
  212. <ControlTemplate TargetType="ToggleButton">
  213. <Border x:Name="BorderRoot" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
  214. <StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}">
  215. <Path x:Name="PathMain" Width="{TemplateBinding hc:IconElement.Width}" Height="{TemplateBinding hc:IconElement.Height}" Fill="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Stretch="Uniform" Data="{TemplateBinding hc:IconElement.Geometry}"/>
  216. <ContentPresenter x:Name="contentPresenter" RecognizesAccessKey="True" VerticalAlignment="Center" Margin="6,0,0,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
  217. </StackPanel>
  218. </Border>
  219. <ControlTemplate.Triggers>
  220. <Trigger Property="IsMouseOver" Value="True">
  221. <Setter Property="TextElement.Foreground" Value="{DynamicResource PrimaryBrush}" TargetName="contentPresenter"/>
  222. </Trigger>
  223. <Trigger Property="IsChecked" Value="true">
  224. <Setter Property="BorderBrush" Value="{Binding Path=(hc:VisualElement.HighlightBorderBrush),RelativeSource={RelativeSource TemplatedParent}}" TargetName="BorderRoot"/>
  225. <Setter Property="Background" Value="{Binding Path=(hc:VisualElement.HighlightBackground),RelativeSource={RelativeSource TemplatedParent}}" TargetName="BorderRoot"/>
  226. <Setter Property="TextElement.Foreground" Value="{Binding Path=(hc:VisualElement.HighlightForeground),RelativeSource={RelativeSource TemplatedParent}}" TargetName="contentPresenter"/>
  227. </Trigger>
  228. <Trigger Property="Content" Value="{x:Null}">
  229. <Setter Property="Visibility" Value="Collapsed" TargetName="contentPresenter"/>
  230. </Trigger>
  231. <Trigger Property="hc:IconElement.Geometry" Value="{x:Null}">
  232. <Setter Property="Visibility" Value="Collapsed" TargetName="PathMain"/>
  233. <Setter Property="Margin" Value="0" TargetName="contentPresenter"/>
  234. </Trigger>
  235. </ControlTemplate.Triggers>
  236. </ControlTemplate>
  237. </Setter.Value>
  238. </Setter>
  239. <Style.Triggers>
  240. <Trigger Property="IsEnabled" Value="False">
  241. <Setter Property="Opacity" Value="0.4"/>
  242. </Trigger>
  243. <Trigger Property="IsChecked" Value="True">
  244. <Setter Property="Panel.ZIndex" Value="{x:Static system:Int32.MaxValue}"/>
  245. </Trigger>
  246. <DataTrigger Binding="{Binding Orientation,RelativeSource={RelativeSource AncestorType=hc:ButtonGroup}}" Value="Vertical">
  247. <Setter Property="Margin" Value="0,-1,0,0"/>
  248. </DataTrigger>
  249. <Trigger Property="IsMouseOver" Value="True">
  250. <Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
  251. </Trigger>
  252. <Trigger Property="IsPressed" Value="True">
  253. <Setter Property="Background" Value="{DynamicResource BorderBrush}"/>
  254. </Trigger>
  255. </Style.Triggers>
  256. </Style>
  257. </ResourceDictionary>