50

I'm using a checkbox control like this:

<CheckBox VerticalAlignment="Bottom" IsChecked="{Binding Selected}" 
      Grid.Column="0" 
      FontSize="{StaticResource PhoneFontSizeLarge}" 
      Content="{Binding Name}">
</CheckBox>

The thing is that I change size to be a little bigger. In this case text is getting bigger, but tick itself remains the same. It looks ugly, can I resize checkbox somehow?

UPDATE I'm doing it on windows phone so LayoutTransform not appropriate here

Sly
  • 15,046
  • 12
  • 60
  • 89
  • Maybe this will help: http://stackoverflow.com/questions/9087063/changing-the-size-of-a-checkbox-and-the-check-mark-in-it – robertk Nov 21 '12 at 06:28

6 Answers6

123

Try some thing like this:-

<CheckBox>
    <CheckBox.LayoutTransform>
        <ScaleTransform ScaleX="2" ScaleY="2" />
    </CheckBox.LayoutTransform>
</CheckBox>

You can also check this link

kdazzle
  • 4,190
  • 3
  • 24
  • 27
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • LayoutTransform is not accessible in windows phone – Sly Nov 20 '12 at 20:23
  • In my experience , the [StackPanel approach](http://stackoverflow.com/a/13484367/350933) from @bmeredith plays much nicer with positioning. The ScaleTransform approach requires margin offsetting to get the output lined up with other controls. – ctrlplusb Jul 25 '15 at 10:36
12
    <StackPanel Height="80"
                Name="StackPanel1"
                Orientation="Horizontal">
        <Viewbox Height="{Binding Path=ActualHeight, ElementName=StackPanel1}">
            <CheckBox />
        </Viewbox>
    </StackPanel>

Adjust the StackPanel height as needed.

bmeredith
  • 655
  • 6
  • 8
  • No offense, but googled and searched for viewbox. Seems right for the question, but I cannot add it on a xaml page. WHY? Am I missing a library. I checked in add Items on toolbar, it was there, but still cannot add it to the page. – Master Chief Nov 21 '12 at 06:55
  • Good question. Although I don't write code for WP7, I was under the assumption Viewbox was made part of WP7 at some point. Maybe check out this link for some ideas. http://www.c-sharpcorner.com/UploadFile/74f20d/working-with-viewbox-control-in-windows-phone-7/ – bmeredith Nov 26 '12 at 02:54
4

Ended up with the following:

  1. Add an empty checkbox
  2. Open control in expression blend
  3. Select checkbox there
  4. Open Edit Template -> Edit Copy
  5. It will create a new style with custom template that you will be able to assign to checkboxes.

It produced about 150 loc style, but I couldn't find another way

Sly
  • 15,046
  • 12
  • 60
  • 89
  • This is the real way to do it. Good explaination :) For lazy people, Shrikant S added the code as an other answer... – Abyte0 Mar 30 '19 at 20:29
3
                ScaleTransform scale = new ScaleTransform(2.0, 2.0);
                yourCheckBox.RenderTransformOrigin = new Point(0.5, 0.5);
                yourCheckBox.RenderTransform = scale;
Péter Hidvégi
  • 743
  • 6
  • 21
3

Just add below mention codes in windows/usercontrol resource, it will automatically increase the default size of the []checkbox inside a Xaml control.

<Style x:Key="FocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <SolidColorBrush x:Key="OptionMark.Static.Background" Color="#FFFFFFFF"/>
    <SolidColorBrush x:Key="OptionMark.Static.Border" Color="#FF707070"/>
    <Style x:Key="OptionMarkFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="14,0,0,0" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <SolidColorBrush x:Key="OptionMark.MouseOver.Background" Color="#FFF3F9FF"/>
    <SolidColorBrush x:Key="OptionMark.MouseOver.Border" Color="#FF5593FF"/>
    <SolidColorBrush x:Key="OptionMark.MouseOver.Glyph" Color="#FF212121"/>
    <SolidColorBrush x:Key="OptionMark.Disabled.Background" Color="#FFE6E6E6"/>
    <SolidColorBrush x:Key="OptionMark.Disabled.Border" Color="#FFBCBCBC"/>
    <SolidColorBrush x:Key="OptionMark.Disabled.Glyph" Color="#FF707070"/>
    <SolidColorBrush x:Key="OptionMark.Pressed.Background" Color="#FFD9ECFF"/>
    <SolidColorBrush x:Key="OptionMark.Pressed.Border" Color="#FF3C77DD"/>
    <SolidColorBrush x:Key="OptionMark.Pressed.Glyph" Color="#FF212121"/>
    <SolidColorBrush x:Key="OptionMark.Static.Glyph" Color="#FF212121"/>
    <Style TargetType="{x:Type CheckBox}">
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
        <Setter Property="Background" Value="{StaticResource OptionMark.Static.Background}"/>
        <Setter Property="BorderBrush" Value="{StaticResource OptionMark.Static.Border}"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type CheckBox}">
                    <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Border x:Name="checkBoxBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                            <Grid x:Name="markGrid">
                                <Path x:Name="optionMark" Data="F1 M 9.97498,1.22334L 4.6983,9.09834L 4.52164,9.09834L 0,5.19331L 1.27664,3.52165L 4.255,6.08833L 8.33331,1.52588e-005L 9.97498,1.22334 Z "
                                      Fill="{StaticResource OptionMark.Pressed.Glyph}" Margin="5" Opacity="0" Stretch="Uniform"/>
                                <Rectangle x:Name="indeterminateMark" Fill="{StaticResource OptionMark.Static.Glyph}" Margin="2" Opacity="0"/>
                            </Grid>
                        </Border>
                        <ContentPresenter x:Name="contentPresenter" Grid.Column="1" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasContent" Value="true">
                            <Setter Property="FocusVisualStyle" Value="{StaticResource OptionMarkFocusVisual}"/>
                            <Setter Property="Padding" Value="4,-1,0,0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.MouseOver.Background}"/>
                            <Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.MouseOver.Border}"/>
                            <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.MouseOver.Glyph}"/>
                            <Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.MouseOver.Glyph}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Disabled.Background}"/>
                            <Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Disabled.Border}"/>
                            <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.Disabled.Glyph}"/>
                            <Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.Disabled.Glyph}"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Pressed.Background}"/>
                            <Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Pressed.Border}"/>
                            <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.Pressed.Glyph}"/>
                            <Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.Pressed.Glyph}"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter Property="Opacity" TargetName="optionMark" Value="1"/>
                            <Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="{x:Null}">
                            <Setter Property="Opacity" TargetName="optionMark" Value="0"/>
                            <Setter Property="Opacity" TargetName="indeterminateMark" Value="1"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
Shrikant S
  • 51
  • 1
  • 4
2

LargeCheckBox

WPF Modified example

  • markGrid Width="24", Height="24"

  • optionMark Margin="4", Stretch="Uniform"

  • indeterminateMark Margin="4"

      <Style x:Key="FocusVisual">
          <Setter Property="Control.Template">
              <Setter.Value>
                  <ControlTemplate>
                      <Rectangle Margin="2" StrokeDashArray="1 2" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" SnapsToDevicePixels="true" StrokeThickness="1"/>
                  </ControlTemplate>
              </Setter.Value>
          </Setter>
      </Style>
      <Style x:Key="OptionMarkFocusVisual">
          <Setter Property="Control.Template">
              <Setter.Value>
                  <ControlTemplate>
                      <Rectangle Margin="14,0,0,0" StrokeDashArray="1 2" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" SnapsToDevicePixels="true" StrokeThickness="1"/>
                  </ControlTemplate>
              </Setter.Value>
          </Setter>
      </Style>
      <SolidColorBrush x:Key="OptionMark.Static.Background" Color="#FFFFFFFF"/>
      <SolidColorBrush x:Key="OptionMark.Static.Border" Color="#FF707070"/>
      <SolidColorBrush x:Key="OptionMark.Static.Glyph" Color="#FF212121"/>
      <SolidColorBrush x:Key="OptionMark.MouseOver.Background" Color="#FFF3F9FF"/>
      <SolidColorBrush x:Key="OptionMark.MouseOver.Border" Color="#FF5593FF"/>
      <SolidColorBrush x:Key="OptionMark.MouseOver.Glyph" Color="#FF212121"/>
      <SolidColorBrush x:Key="OptionMark.Pressed.Background" Color="#FFD9ECFF"/>
      <SolidColorBrush x:Key="OptionMark.Pressed.Border" Color="#FF3C77DD"/>
      <SolidColorBrush x:Key="OptionMark.Pressed.Glyph" Color="#FF212121"/>
      <SolidColorBrush x:Key="OptionMark.Disabled.Background" Color="#FFE6E6E6"/>
      <SolidColorBrush x:Key="OptionMark.Disabled.Border" Color="#FFBCBCBC"/>
      <SolidColorBrush x:Key="OptionMark.Disabled.Glyph" Color="#FF707070"/>
      <Style x:Key="CheckBoxLarge" TargetType="{x:Type CheckBox}">
          <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
          <Setter Property="Background" Value="{StaticResource OptionMark.Static.Background}"/>
          <Setter Property="BorderBrush" Value="{StaticResource OptionMark.Static.Border}"/>
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
          <Setter Property="BorderThickness" Value="1"/>
          <Setter Property="Template">
              <Setter.Value>
                  <ControlTemplate TargetType="{x:Type CheckBox}">
                      <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
                          <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="Auto"/>
                              <ColumnDefinition Width="*"/>
                          </Grid.ColumnDefinitions>
                          <Border x:Name="checkBoxBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                              <Grid x:Name="markGrid" Width="24" Height="24">
                                  <!--  Width,Height,Stretch="Uniform",Margin  -->
                                  <Path x:Name="optionMark" Data="F1 M 9.97498,1.22334L 4.6983,9.09834L 4.52164,9.09834L 0,5.19331L 1.27664,3.52165L 4.255,6.08833L 8.33331,1.52588e-005L 9.97498,1.22334 Z " Fill="{StaticResource OptionMark.Static.Glyph}" Margin="4" Opacity="0" Stretch="Uniform"/>
                                  <Rectangle x:Name="indeterminateMark" Fill="{StaticResource OptionMark.Static.Glyph}" Margin="4" Opacity="0"/>
                              </Grid>
                          </Border>
                          <ContentPresenter x:Name="contentPresenter" Grid.Column="1" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                      </Grid>
                      <ControlTemplate.Triggers>
                          <Trigger Property="HasContent" Value="true">
                              <Setter Property="FocusVisualStyle" Value="{StaticResource OptionMarkFocusVisual}"/>
                              <Setter Property="Padding" Value="4,-1,0,0"/>
                          </Trigger>
                          <Trigger Property="IsMouseOver" Value="true">
                              <Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.MouseOver.Background}"/>
                              <Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.MouseOver.Border}"/>
                              <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.MouseOver.Glyph}"/>
                              <Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.MouseOver.Glyph}"/>
                          </Trigger>
                          <Trigger Property="IsEnabled" Value="false">
                              <Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Disabled.Background}"/>
                              <Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Disabled.Border}"/>
                              <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.Disabled.Glyph}"/>
                              <Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.Disabled.Glyph}"/>
                          </Trigger>
                          <Trigger Property="IsPressed" Value="true">
                              <Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Pressed.Background}"/>
                              <Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Pressed.Border}"/>
                              <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.Pressed.Glyph}"/>
                              <Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.Pressed.Glyph}"/>
                          </Trigger>
                          <Trigger Property="IsChecked" Value="true">
                              <Setter Property="Opacity" TargetName="optionMark" Value="1"/>
                              <Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/>
                          </Trigger>
                          <Trigger Property="IsChecked" Value="{x:Null}">
                              <Setter Property="Opacity" TargetName="optionMark" Value="0"/>
                              <Setter Property="Opacity" TargetName="indeterminateMark" Value="1"/>
                          </Trigger>
                      </ControlTemplate.Triggers>
                  </ControlTemplate>
              </Setter.Value>
          </Setter>
      </Style>
    
hiro.t
  • 41
  • 1
  • 8