CheckBox.xaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  2. <Design.PreviewWith>
  3. <Border Padding="20">
  4. <CheckBox IsThreeState="True" IsChecked="True" Content="Content" Foreground="Gold" />
  5. </Border>
  6. </Design.PreviewWith>
  7. <Style Selector="CheckBox">
  8. <Setter Property="Padding" Value="8,0,0,0" />
  9. <Setter Property="HorizontalAlignment" Value="Left" />
  10. <Setter Property="VerticalAlignment" Value="Center" />
  11. <Setter Property="HorizontalContentAlignment" Value="Left" />
  12. <Setter Property="VerticalContentAlignment" Value="Center" />
  13. <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
  14. <Setter Property="MinWidth" Value="120" />
  15. <Setter Property="MinHeight" Value="32" />
  16. <!--<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
  17. <Setter Property="FocusVisualMargin" Value="-7,-3,-7,-3" />-->
  18. <Setter Property="Template">
  19. <ControlTemplate>
  20. <Grid x:Name="RootGrid" ColumnDefinitions="20,*">
  21. <Border x:Name="PART_Border"
  22. Grid.ColumnSpan="2"
  23. Background="{TemplateBinding Background}"
  24. BorderBrush="{TemplateBinding BorderBrush}"
  25. BorderThickness="{TemplateBinding BorderThickness}" />
  26. <Grid VerticalAlignment="Top" Height="32">
  27. <Border x:Name="NormalRectangle"
  28. BorderThickness="{DynamicResource CheckBoxBorderThemeThickness}"
  29. UseLayoutRounding="False"
  30. Height="20"
  31. Width="20" />
  32. <Viewbox UseLayoutRounding="False">
  33. <Panel>
  34. <Panel Height="16" Width="16" />
  35. <Path x:Name="CheckGlyph" Stretch="Uniform" VerticalAlignment="Center" />
  36. </Panel>
  37. </Viewbox>
  38. </Grid>
  39. <ContentPresenter x:Name="ContentPresenter"
  40. ContentTemplate="{TemplateBinding ContentTemplate}"
  41. Content="{TemplateBinding Content}"
  42. Margin="{TemplateBinding Padding}"
  43. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  44. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  45. Grid.Column="1" />
  46. <!-- TODO: TextWrapping="Wrap" on contentpresenter -->
  47. </Grid>
  48. </ControlTemplate>
  49. </Setter>
  50. </Style>
  51. <Style Selector="CheckBox /template/ Border#PART_Border">
  52. <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
  53. </Style>
  54. <Style Selector="CheckBox /template/ Border#NormalRectangle">
  55. <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
  56. </Style>
  57. <!-- Unchecked Normal State -->
  58. <Style Selector="CheckBox">
  59. <Setter Property="Foreground" Value="{DynamicResource CheckBoxForegroundUnchecked}" />
  60. </Style>
  61. <Style Selector="CheckBox">
  62. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundUnchecked}" />
  63. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushUnchecked}" />
  64. </Style>
  65. <Style Selector="CheckBox /template/ Border#NormalRectangle">
  66. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeUnchecked}" />
  67. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillUnchecked}" />
  68. </Style>
  69. <Style Selector="CheckBox /template/ Path#CheckGlyph">
  70. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundUnchecked}" />
  71. <Setter Property="Opacity" Value="0" />
  72. </Style>
  73. <!-- Unchecked PointerOver State -->
  74. <Style Selector="CheckBox:pointerover /template/ ContentPresenter#ContentPresenter">
  75. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundUncheckedPointerOver}" />
  76. </Style>
  77. <Style Selector="CheckBox:pointerover /template/ Border#PART_Border">
  78. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundUncheckedPointerOver}" />
  79. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushUncheckedPointerOver}" />
  80. </Style>
  81. <Style Selector="CheckBox:pointerover /template/ Border#NormalRectangle">
  82. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeUncheckedPointerOver}" />
  83. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillUncheckedPointerOver}" />
  84. </Style>
  85. <Style Selector="CheckBox:pointerover /template/ Path#CheckGlyph">
  86. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundUncheckedPointerOver}" />
  87. </Style>
  88. <!-- Unchecked Pressed State -->
  89. <Style Selector="CheckBox:pressed /template/ ContentPresenter#ContentPresenter">
  90. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundUncheckedPressed}" />
  91. </Style>
  92. <Style Selector="CheckBox:pressed /template/ Border#PART_Border">
  93. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundUncheckedPressed}" />
  94. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushUncheckedPressed}" />
  95. </Style>
  96. <Style Selector="CheckBox:pressed /template/ Border#NormalRectangle">
  97. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeUncheckedPressed}" />
  98. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillUncheckedPressed}" />
  99. </Style>
  100. <Style Selector="CheckBox:pressed /template/ Path#CheckGlyph">
  101. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundUncheckedPressed}" />
  102. </Style>
  103. <!-- Unchecked Disabled state -->
  104. <Style Selector="CheckBox:disabled /template/ ContentPresenter#ContentPresenter">
  105. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundUncheckedDisabled}" />
  106. </Style>
  107. <Style Selector="CheckBox:disabled /template/ Border#PART_Border">
  108. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundUncheckedDisabled}" />
  109. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushUncheckedDisabled}" />
  110. </Style>
  111. <Style Selector="CheckBox:disabled /template/ Border#NormalRectangle">
  112. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeUncheckedDisabled}" />
  113. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillUncheckedDisabled}" />
  114. </Style>
  115. <Style Selector="CheckBox:disabled /template/ Path#CheckGlyph">
  116. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundUncheckedDisabled}" />
  117. </Style>
  118. <!-- Checked Normal State -->
  119. <Style Selector="CheckBox:checked">
  120. <Setter Property="Foreground" Value="{DynamicResource CheckBoxForegroundChecked}" />
  121. </Style>
  122. <Style Selector="CheckBox:checked">
  123. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundChecked}" />
  124. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushChecked}" />
  125. </Style>
  126. <Style Selector="CheckBox:checked /template/ Border#NormalRectangle">
  127. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundFillChecked}" />
  128. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillChecked}" />
  129. </Style>
  130. <Style Selector="CheckBox:checked /template/ Path#CheckGlyph">
  131. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundChecked}" />
  132. <Setter Property="Data" Value="M1507 31L438 1101L-119 543L-29 453L438 919L1417 -59L1507 31Z" />
  133. <Setter Property="Width" Value="9" />
  134. <Setter Property="Opacity" Value="1" />
  135. </Style>
  136. <!-- Checked PointerOver State -->
  137. <Style Selector="CheckBox:checked:pointerover /template/ ContentPresenter#ContentPresenter">
  138. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundCheckedPointerOver}" />
  139. </Style>
  140. <Style Selector="CheckBox:checked:pointerover /template/ Border#PART_Border">
  141. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundCheckedPointerOver}" />
  142. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushCheckedPointerOver}" />
  143. </Style>
  144. <Style Selector="CheckBox:checked:pointerover /template/ Border#NormalRectangle">
  145. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeCheckedPointerOver}" />
  146. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillCheckedPointerOver}" />
  147. </Style>
  148. <Style Selector="CheckBox:checked:pointerover /template/ Path#CheckGlyph">
  149. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundCheckedPointerOver}" />
  150. </Style>
  151. <!-- Checked Pressed State -->
  152. <Style Selector="CheckBox:checked:pressed /template/ ContentPresenter#ContentPresenter">
  153. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundCheckedPressed}" />
  154. </Style>
  155. <Style Selector="CheckBox:checked:pressed /template/ Border#PART_Border">
  156. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundCheckedPressed}" />
  157. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushCheckedPressed}" />
  158. </Style>
  159. <Style Selector="CheckBox:checked:pressed /template/ Border#NormalRectangle">
  160. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeCheckedPressed}" />
  161. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillCheckedPressed}" />
  162. </Style>
  163. <Style Selector="CheckBox:checked:pressed /template/ Path#CheckGlyph">
  164. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundCheckedPressed}" />
  165. </Style>
  166. <!-- Checked Disabled State -->
  167. <Style Selector="CheckBox:checked:disabled /template/ ContentPresenter#ContentPresenter">
  168. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundCheckedDisabled}" />
  169. </Style>
  170. <Style Selector="CheckBox:checked:disabled /template/ Border#PART_Border">
  171. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundCheckedDisabled}" />
  172. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushCheckedDisabled}" />
  173. </Style>
  174. <Style Selector="CheckBox:checked:disabled /template/ Border#NormalRectangle">
  175. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeCheckedDisabled}" />
  176. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillCheckedDisabled}" />
  177. </Style>
  178. <Style Selector="CheckBox:checked:disabled /template/ Path#CheckGlyph">
  179. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundCheckedDisabled}" />
  180. </Style>
  181. <!-- Indeterminate Normal State -->
  182. <Style Selector="CheckBox:indeterminate">
  183. <Setter Property="Foreground" Value="{DynamicResource CheckBoxForegroundIndeterminate}" />
  184. </Style>
  185. <Style Selector="CheckBox:indeterminate">
  186. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundIndeterminate}" />
  187. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushIndeterminate}" />
  188. </Style>
  189. <Style Selector="CheckBox:indeterminate /template/ Border#NormalRectangle">
  190. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeIndeterminate}" />
  191. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillIndeterminate}" />
  192. </Style>
  193. <Style Selector="CheckBox:indeterminate /template/ Path#CheckGlyph">
  194. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundIndeterminate}" />
  195. <Setter Property="Data" Value="M1536 1536v-1024h-1024v1024h1024z" />
  196. <Setter Property="Width" Value="7" />
  197. <Setter Property="Opacity" Value="1" />
  198. </Style>
  199. <!-- Indeterminate PointerOver State -->
  200. <Style Selector="CheckBox:indeterminate:pointerover /template/ ContentPresenter#ContentPresenter">
  201. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundIndeterminatePointerOver}" />
  202. </Style>
  203. <Style Selector="CheckBox:indeterminate:pointerover /template/ Border#PART_Border">
  204. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundIndeterminatePointerOver}" />
  205. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushIndeterminatePointerOver}" />
  206. </Style>
  207. <Style Selector="CheckBox:indeterminate:pointerover /template/ Border#NormalRectangle">
  208. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeIndeterminatePointerOver}" />
  209. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillIndeterminatePointerOver}" />
  210. </Style>
  211. <Style Selector="CheckBox:indeterminate:pointerover /template/ Path#CheckGlyph">
  212. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundIndeterminatePointerOver}" />
  213. </Style>
  214. <!-- Indeterminate Pressed State -->
  215. <Style Selector="CheckBox:indeterminate:pressed /template/ ContentPresenter#ContentPresenter">
  216. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundIndeterminatePressed}" />
  217. </Style>
  218. <Style Selector="CheckBox:indeterminate:pressed /template/ Border#PART_Border">
  219. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundIndeterminatePressed}" />
  220. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushIndeterminatePressed}" />
  221. </Style>
  222. <Style Selector="CheckBox:indeterminate:pressed /template/ Border#NormalRectangle">
  223. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeIndeterminatePressed}" />
  224. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillIndeterminatePressed}" />
  225. </Style>
  226. <Style Selector="CheckBox:indeterminate:pressed /template/ Path#CheckGlyph">
  227. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundIndeterminatePressed}" />
  228. </Style>
  229. <!-- Indeterminate Disabled State -->
  230. <Style Selector="CheckBox:indeterminate:disabled /template/ ContentPresenter#ContentPresenter">
  231. <Setter Property="TextBlock.Foreground" Value="{DynamicResource CheckBoxForegroundIndeterminateDisabled}" />
  232. </Style>
  233. <Style Selector="CheckBox:indeterminate:disabled /template/ Border#PART_Border">
  234. <Setter Property="Background" Value="{DynamicResource CheckBoxBackgroundIndeterminateDisabled}" />
  235. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxBorderBrushIndeterminateDisabled}" />
  236. </Style>
  237. <Style Selector="CheckBox:indeterminate:disabled /template/ Border#NormalRectangle">
  238. <Setter Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBackgroundStrokeIndeterminateDisabled}" />
  239. <Setter Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillIndeterminateDisabled}" />
  240. </Style>
  241. <Style Selector="CheckBox:indeterminate:disabled /template/ Path#CheckGlyph">
  242. <Setter Property="Fill" Value="{DynamicResource CheckBoxCheckGlyphForegroundIndeterminateDisabled}" />
  243. </Style>
  244. </Styles>