Search code examples
c#wpfcheckboxcheckmark

Change the size of CheckBox's CheckMark WPF


I have implemented this style for my CheckBox:

<Style x:Key="{x:Type CheckBox}" TargetType="CheckBox">
  <Setter Property="SnapsToDevicePixels" Value="true"/>
  <Setter Property="OverridesDefaultStyle" Value="true"/>
  <Setter Property="FontFamily" Value="{DynamicResource MetroFontRegular}"/>
  <Setter Property="FocusVisualStyle" Value="{StaticResource CheckBoxFocusVisual}"/>
  <Setter Property="Foreground" Value="#999999"/>
  <Setter Property="Background" Value="#3f3f3f"/>
  <Setter Property="FontSize" Value="12"/>
  <Setter Property="VerticalContentAlignment" Value="Center"/>
  <Setter Property="Template">
   <Setter.Value>
   <ControlTemplate TargetType="CheckBox">
     <BulletDecorator Background="Transparent">
       <BulletDecorator.Bullet>
         <Border x:Name="Border"  
                 Width="13" 
                 Height="13" 
                 CornerRadius="6,6,6,6"
                 Background="#ffffff"
                 BorderBrush="#999999"
                 BorderThickness="1" >
             <Image x:Name="CheckMark" Source="Images/CheckMark.png" Width="15" Height="15" HorizontalAlignment="Center" VerticalAlignment="Center"/>
          </Border>
       </BulletDecorator.Bullet>
       <ContentPresenter Margin="8,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" RecognizesAccessKey="True"/>
    </BulletDecorator>
    <ControlTemplate.Triggers>
      <Trigger Property="IsChecked" Value="false">
        <Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/>
      </Trigger>
      <Trigger Property="IsMouseOver" Value="true">
        <Setter TargetName="Border" Property="Background" Value="#91814E" />
      </Trigger>
      <Trigger Property="IsEnabled" Value="false">
        <Setter Property="Foreground" Value="#c1c1c1"/>
      </Trigger>
   </ControlTemplate.Triggers>
 </ControlTemplate>
</Setter.Value>
</Setter>
</Style>

So now my checkbox looks like a circle and it's checkmark is actually an image named "CheckMark". So I'm pleased with it's look but what i would like to manage is to make my checkmark little bit bigger than my checkbox. For example something like this:

enter image description here

I tried to change the size of my image but when I change it it only get changed inside of checkbox. It does't get outside of it's border. How can I manage this?


Solution

  • If your Border element is constraining the size of the Image that is declared inside it, you can simply move the Image outside of the Border and increase it's size:

    <Border x:Name="Border"  
                Width="13" 
                Height="13" 
                CornerRadius="6,6,6,6"
                Background="#ffffff"
                BorderBrush="#999999"
                BorderThickness="1" >
    </Border>
    <Image x:Name="CheckMark" Source="Images/CheckMark.png" Width="30" Height="30" 
        HorizontalAlignment="Center" VerticalAlignment="Center"/>