ToggleButtonStyles.xaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  2. <Design.PreviewWith>
  3. <StackPanel Width="250"
  4. Margin="20"
  5. Background="{DynamicResource SukiBackground}"
  6. Spacing="24">
  7. <ToggleButton Classes="Switch" IsChecked="False" />
  8. <ToggleButton Content="Test" />
  9. </StackPanel>
  10. </Design.PreviewWith>
  11. <Style Selector="ToggleButton">
  12. <Setter Property="CornerRadius" Value="8" />
  13. <Setter Property="BorderThickness" Value="1" />
  14. <Setter Property="BorderBrush" Value="{DynamicResource SukiControlBorderBrush}" />
  15. <Setter Property="Background" Value="Transparent" />
  16. <Setter Property="Padding" Value="18,10,18,8" />
  17. <Setter Property="FontWeight" Value="{DynamicResource DefaultDemiBold}" />
  18. <Setter Property="FontSize" Value="14" />
  19. <Setter Property="Foreground" Value="{DynamicResource SukiText}" />
  20. <Setter Property="Transitions">
  21. <Transitions>
  22. <BrushTransition Property="Background" Duration="0:0:0.3" />
  23. <BrushTransition Property="BorderBrush" Duration="0:0:0.3" />
  24. </Transitions>
  25. </Setter>
  26. <Setter Property="Template">
  27. <ControlTemplate>
  28. <ContentPresenter Padding="{TemplateBinding Padding}"
  29. HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
  30. VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
  31. Background="{TemplateBinding Background}"
  32. BorderBrush="{TemplateBinding BorderBrush}"
  33. BorderThickness="{TemplateBinding BorderThickness}"
  34. Content="{TemplateBinding Content}"
  35. ContentTemplate="{TemplateBinding ContentTemplate}"
  36. CornerRadius="{TemplateBinding CornerRadius}"
  37. FontSize="{TemplateBinding FontSize}"
  38. Foreground="{TemplateBinding Foreground}"
  39. RecognizesAccessKey="True"
  40. TextElement.Foreground="{TemplateBinding Foreground}" />
  41. </ControlTemplate>
  42. </Setter>
  43. </Style>
  44. <Style Selector="ToggleButton:pointerover &gt; TextBlock">
  45. <Setter Property="Foreground" Value="White" />
  46. </Style>
  47. <Style Selector="ToggleButton AccessText">
  48. <Setter Property="Foreground" Value="{DynamicResource SukiText}" />
  49. <Setter Property="Transitions">
  50. <Transitions>
  51. <BrushTransition Property="Foreground" Duration="0:0:0.3" />
  52. </Transitions>
  53. </Setter>
  54. </Style>
  55. <Style Selector="ToggleButton:checked AccessText">
  56. <Setter Property="Foreground" Value="White" />
  57. </Style>
  58. <Style Selector="ToggleButton:pointerover AccessText">
  59. <Setter Property="Foreground" Value="White" />
  60. </Style>
  61. <Style Selector="ToggleButton:pointerover">
  62. <Setter Property="Background" Value="{DynamicResource SukiPrimaryColor75}" />
  63. <Setter Property="Foreground" Value="White" />
  64. <Style Selector="^.Accent">
  65. <Setter Property="Background" Value="{DynamicResource SukiAccentColor75}" />
  66. </Style>
  67. </Style>
  68. <Style Selector="ToggleButton:checked">
  69. <Setter Property="Foreground" Value="White" />
  70. <Setter Property="Background" Value="{DynamicResource SukiPrimaryColor}" />
  71. <Setter Property="BorderBrush" Value="{DynamicResource SukiPrimaryColor}" />
  72. <Style Selector="^.Accent">
  73. <Setter Property="Background" Value="{DynamicResource SukiAccentColor}" />
  74. <Setter Property="BorderBrush" Value="{DynamicResource SukiAccentColor}" />
  75. </Style>
  76. </Style>
  77. <Style Selector="ToggleButton:pointerover[IsChecked=True]">
  78. <Setter Property="Background" Value="{DynamicResource SukiPrimaryColor75}" />
  79. <Style Selector="^.Accent">
  80. <Setter Property="Background" Value="{DynamicResource SukiAccentColor75}" />
  81. </Style>
  82. </Style>
  83. <Style Selector="ToggleButton.Switch">
  84. <Setter Property="Foreground" Value="{DynamicResource SukiPrimaryColor}" />
  85. <Setter Property="RenderTransform">
  86. <ScaleTransform ScaleX="1.15" ScaleY="1.15" />
  87. </Setter>
  88. <Setter Property="HorizontalAlignment" Value="Left" />
  89. <Setter Property="VerticalAlignment" Value="Center" />
  90. <Setter Property="HorizontalContentAlignment" Value="Left" />
  91. <Setter Property="VerticalContentAlignment" Value="Center" />
  92. <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
  93. <Setter Property="Template">
  94. <ControlTemplate>
  95. <Grid Background="Transparent" RowDefinitions="Auto,*">
  96. <ContentPresenter x:Name="PART_ContentPresenter"
  97. Grid.Row="0"
  98. VerticalAlignment="Top"
  99. Content="{TemplateBinding Content}"
  100. ContentTemplate="{TemplateBinding ContentTemplate}"
  101. RecognizesAccessKey="True" />
  102. <Grid Grid.Row="1"
  103. MinWidth="{DynamicResource ToggleSwitchThemeMinWidth}"
  104. HorizontalAlignment="Left"
  105. VerticalAlignment="Top">
  106. <Grid.RowDefinitions>
  107. <RowDefinition Height="{DynamicResource ToggleSwitchPreContentMargin}" />
  108. <RowDefinition Height="Auto" />
  109. <RowDefinition Height="{DynamicResource ToggleSwitchPostContentMargin}" />
  110. </Grid.RowDefinitions>
  111. <Grid.ColumnDefinitions>
  112. <ColumnDefinition Width="Auto" />
  113. <ColumnDefinition Width="12" MaxWidth="12" />
  114. <ColumnDefinition Width="Auto" />
  115. </Grid.ColumnDefinitions>
  116. <Grid x:Name="SwitchAreaGrid"
  117. Grid.RowSpan="3"
  118. Grid.ColumnSpan="3"
  119. Margin="0,5"
  120. TemplatedControl.IsTemplateFocusTarget="True" />
  121. <Border x:Name="OuterBorder"
  122. Grid.Row="1"
  123. Width="40"
  124. Height="20"
  125. Background="{DynamicResource SukiControlBorderBrush}"
  126. BorderThickness="0"
  127. CornerRadius="{DynamicResource MediumCornerRadius}">
  128. <Border.Transitions>
  129. <Transitions>
  130. <DoubleTransition Property="Opacity" Duration="0:0:0.15" />
  131. </Transitions>
  132. </Border.Transitions>
  133. </Border>
  134. <Border x:Name="SwitchBackground"
  135. Grid.Row="1"
  136. Width="40"
  137. Height="20"
  138. Background="{DynamicResource SukiControlBorderBrush}"
  139. BorderThickness="0"
  140. CornerRadius="{DynamicResource MediumCornerRadius}">
  141. <Border.Transitions>
  142. <Transitions>
  143. <DoubleTransition Property="Opacity" Duration="0:0:0.15" />
  144. <BrushTransition Property="Background" Duration="0:0:0.15" />
  145. </Transitions>
  146. </Border.Transitions>
  147. </Border>
  148. <Canvas x:Name="PART_SwitchKnob"
  149. Grid.Row="1"
  150. Width="20"
  151. Height="20"
  152. HorizontalAlignment="Left">
  153. <Border x:Name="SwitchKnob"
  154. Canvas.Left="2"
  155. Canvas.Top="2"
  156. Width="16"
  157. Height="16"
  158. Margin="0,0,0,0"
  159. Background="#fcfcfc"
  160. BoxShadow="{DynamicResource SukiSwitchShadow}"
  161. CornerRadius="{DynamicResource MediumCornerRadius}">
  162. <Border />
  163. <Border.Transitions>
  164. <Transitions />
  165. </Border.Transitions>
  166. </Border>
  167. </Canvas>
  168. </Grid>
  169. </Grid>
  170. </ControlTemplate>
  171. </Setter>
  172. </Style>
  173. <Style Selector="ToggleButton.Switch:unchecked /template/ Border#SwitchKnob">
  174. <Style.Animations>
  175. <Animation FillMode="Both" Duration="0:0:0.4">
  176. <Animation.Easing>
  177. <QuadraticEaseOut />
  178. </Animation.Easing>
  179. <KeyFrame Cue="30%">
  180. <Setter Property="Width" Value="22" />
  181. <Setter Property="Canvas.Left" Value="11" />
  182. </KeyFrame>
  183. <KeyFrame Cue="70%">
  184. <Setter Property="Width" Value="22" />
  185. <Setter Property="Canvas.Left" Value="2" />
  186. </KeyFrame>
  187. <KeyFrame Cue="100%">
  188. <Setter Property="Width" Value="16" />
  189. <Setter Property="Canvas.Left" Value="2" />
  190. </KeyFrame>
  191. </Animation>
  192. </Style.Animations>
  193. </Style>
  194. <Style Selector="ToggleButton.Switch:checked /template/ Border#SwitchKnob">
  195. <Setter Property="BoxShadow" Value="0 0 0 0 White" />
  196. <Style.Animations>
  197. <Animation FillMode="Both" Duration="0:0:0.4">
  198. <Animation.Easing>
  199. <QuadraticEaseOut />
  200. </Animation.Easing>
  201. <KeyFrame Cue="30%">
  202. <Setter Property="Width" Value="22" />
  203. <Setter Property="Canvas.Left" Value="2" />
  204. </KeyFrame>
  205. <KeyFrame Cue="60%">
  206. <Setter Property="Width" Value="20" />
  207. <Setter Property="Canvas.Left" Value="11" />
  208. </KeyFrame>
  209. <KeyFrame Cue="80%">
  210. <Setter Property="Width" Value="18" />
  211. </KeyFrame>
  212. <KeyFrame Cue="90%">
  213. <Setter Property="Width" Value="16" />
  214. </KeyFrame>
  215. <KeyFrame Cue="100%">
  216. <Setter Property="Width" Value="16" />
  217. <Setter Property="Canvas.Left" Value="22" />
  218. </KeyFrame>
  219. </Animation>
  220. </Style.Animations>
  221. </Style>
  222. <!-- <Style Selector="ToggleButton.Switch:pressed[IsChecked=False] /template/ Border#SwitchKnob">
  223. <Style.Animations>
  224. <Animation FillMode="Forward" Duration="0:0:0.15">
  225. <KeyFrame Cue="0%">
  226. <Setter Property="Width" Value="16" />
  227. </KeyFrame>
  228. <KeyFrame Cue="100%">
  229. <Setter Property="Width" Value="20" />
  230. </KeyFrame>
  231. </Animation>
  232. </Style.Animations>
  233. </Style>
  234. <Style Selector="ToggleButton.Switch:pressed[IsChecked=True] /template/ Border#SwitchKnob">
  235. <Style.Animations>
  236. <Animation FillMode="Forward" Duration="0:0:0.1">
  237. <KeyFrame Cue="0%">
  238. <Setter Property="Width" Value="16" />
  239. <Setter Property="Canvas.Left" Value="22" />
  240. </KeyFrame>
  241. <KeyFrame Cue="100%">
  242. <Setter Property="Width" Value="20" />
  243. <Setter Property="Canvas.Left" Value="18" />
  244. </KeyFrame>
  245. </Animation>
  246. </Style.Animations>
  247. <Setter Property="Width" Value="20" />
  248. </Style> -->
  249. <Style Selector="ToggleButton.Switch:checked /template/ Border#SwitchBackground">
  250. <Setter Property="Background" Value="{DynamicResource SukiPrimaryColor}" />
  251. </Style>
  252. <Style Selector="ToggleButton.Basic">
  253. <Setter Property="BorderThickness" Value="0" />
  254. <Setter Property="BorderBrush" Value="Transparent" />
  255. <Setter Property="Padding" Value="11,8" />
  256. <Setter Property="CornerRadius" Value="5" />
  257. <Setter Property="Background" Value="Transparent" />
  258. <Style Selector="^:checked">
  259. <Setter Property="Background" Value="Transparent" />
  260. <Setter Property="Foreground" Value="{DynamicResource SukiText}" />
  261. </Style>
  262. <Style Selector="^:pointerover">
  263. <Setter Property="Background" Value="Transparent" />
  264. <Setter Property="Foreground" Value="{DynamicResource SukiText}" />
  265. </Style>
  266. <Style Selector="^:checked">
  267. <Setter Property="Background" Value="Transparent" />
  268. </Style>
  269. <Style Selector="^:pointerover PathIcon">
  270. <Setter Property="Foreground" Value="{DynamicResource SukiPrimaryColor}" />
  271. <Setter Property="Transitions">
  272. <Setter.Value>
  273. <Transitions>
  274. <BrushTransition Property="Foreground" Duration="0.15" />
  275. </Transitions>
  276. </Setter.Value>
  277. </Setter>
  278. </Style>
  279. </Style>
  280. </Styles>