CheckBoxBaseStyle.xaml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. <Style x:Key="CheckBoxBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="CheckBox">
  5. <Setter Property="FocusVisualStyle">
  6. <Setter.Value>
  7. <Style>
  8. <Setter Property="Control.Template">
  9. <Setter.Value>
  10. <ControlTemplate>
  11. <Rectangle Margin="-4" Opacity=".6" SnapsToDevicePixels="true" Stroke="{DynamicResource SecondaryBorderBrush}" StrokeThickness="2" StrokeDashArray="1 1" RadiusX="4" RadiusY="4" />
  12. </ControlTemplate>
  13. </Setter.Value>
  14. </Setter>
  15. </Style>
  16. </Setter.Value>
  17. </Setter>
  18. <Setter Property="Background" Value="White" />
  19. <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
  20. <Setter Property="BorderThickness" Value="1" />
  21. <Setter Property="HorizontalAlignment" Value="Stretch" />
  22. <Setter Property="VerticalAlignment" Value="Center" />
  23. <Setter Property="VerticalContentAlignment" Value="Center" />
  24. <Setter Property="Padding" Value="6,0,0,0" />
  25. <Setter Property="Template">
  26. <Setter.Value>
  27. <ControlTemplate TargetType="CheckBox">
  28. <ControlTemplate.Resources>
  29. <Storyboard x:Key="StoryboardCheckedTrue">
  30. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeDashOffset)" Storyboard.TargetName="path">
  31. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0" />
  32. </DoubleAnimationUsingKeyFrames>
  33. </Storyboard>
  34. <Storyboard x:Key="StoryboardCheckedFalse">
  35. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeDashOffset)" Storyboard.TargetName="path">
  36. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="8" />
  37. </DoubleAnimationUsingKeyFrames>
  38. </Storyboard>
  39. </ControlTemplate.Resources>
  40. <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
  41. <Grid.ColumnDefinitions>
  42. <ColumnDefinition Width="Auto" />
  43. <ColumnDefinition Width="*" />
  44. </Grid.ColumnDefinitions>
  45. <Border Height="16" Width="16" Background="{TemplateBinding Background}" CornerRadius="2" />
  46. <hc:SimplePanel Grid.Column="0" Height="16" Width="16" x:Name="markGrid">
  47. <Path FlowDirection="LeftToRight" UseLayoutRounding="True" x:Name="path" StrokeDashOffset="8" StrokeDashArray="8,8" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}" />
  48. <Rectangle x:Name="indeterminateMark" RadiusX="2" RadiusY="2" Fill="{DynamicResource PrimaryBrush}" Margin="2" Opacity="0" />
  49. </hc:SimplePanel>
  50. <Border Height="16" Width="16" x:Name="border" CornerRadius="2" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" />
  51. <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}" />
  52. </Grid>
  53. <ControlTemplate.Triggers>
  54. <Trigger Property="HasContent" Value="true">
  55. <Setter Property="Visibility" TargetName="contentPresenter" Value="Visible" />
  56. </Trigger>
  57. <Trigger Property="IsMouseOver" Value="true">
  58. <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderBrush}" />
  59. </Trigger>
  60. <MultiTrigger>
  61. <MultiTrigger.Conditions>
  62. <Condition Property="IsChecked" Value="true" />
  63. <Condition Property="IsPressed" Value="true" />
  64. </MultiTrigger.Conditions>
  65. <Setter Property="Opacity" Value=".8" />
  66. </MultiTrigger>
  67. <MultiTrigger>
  68. <MultiTrigger.Conditions>
  69. <Condition Property="IsChecked" Value="false" />
  70. <Condition Property="IsPressed" Value="true" />
  71. </MultiTrigger.Conditions>
  72. <Setter Property="BorderBrush" Value="{DynamicResource PrimaryBrush}" />
  73. </MultiTrigger>
  74. <Trigger Property="IsChecked" Value="true">
  75. <Trigger.EnterActions>
  76. <BeginStoryboard Storyboard="{StaticResource StoryboardCheckedTrue}" />
  77. </Trigger.EnterActions>
  78. <Trigger.ExitActions>
  79. <BeginStoryboard Storyboard="{StaticResource StoryboardCheckedFalse}" />
  80. </Trigger.ExitActions>
  81. <Setter Property="Opacity" TargetName="indeterminateMark" Value="0" />
  82. <Setter Property="Background" Value="{DynamicResource PrimaryBrush}" />
  83. <Setter Property="BorderBrush" Value="{DynamicResource DarkPrimaryBrush}" />
  84. <Setter TargetName="border" Property="Visibility" Value="Collapsed" />
  85. </Trigger>
  86. <Trigger Property="IsChecked" Value="false">
  87. <Setter Property="Stroke" Value="{DynamicResource BorderBrush}" TargetName="path" />
  88. </Trigger>
  89. <Trigger Property="IsChecked" Value="{x:Null}">
  90. <Setter Property="Opacity" TargetName="indeterminateMark" Value="1" />
  91. </Trigger>
  92. <Trigger Property="IsEnabled" Value="False">
  93. <Setter Property="Opacity" Value="0.4" />
  94. </Trigger>
  95. </ControlTemplate.Triggers>
  96. </ControlTemplate>
  97. </Setter.Value>
  98. </Setter>
  99. </Style>
  100. </ResourceDictionary>