Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default style of CheckBox control in Universal Windows Platform?

I don't know how to change the Checkbox's Default color.I coded this line for Checkbox

<CheckBox  x:Name="chkRememberme" Foreground="Gray"  Grid.Row="4" Background="Transparent"   IsChecked="False" TabIndex="3"  HorizontalAlignment="Center" VerticalAlignment="Top" Background="Blue"   Margin="0,2,0,0"  />

In the below image, I have mentioned the style of Checkbox I require.

enter image description here

like image 542
Hardik Kothari Avatar asked Dec 06 '25 16:12

Hardik Kothari


1 Answers

Open designer window, right click on your CheckBox, then choose Edit template -> Edit a copy (or do the same in Blend). This should create default style in your resources (you can find the style also here at MSDN).

In the style you will find everything you want. The background color you are looking for is changed by VisualStateManager - edit suitable visual states and it should work. Sample - changed value of NormalRectangle.Fill property to SystemControlBackgroundBaseLowBrush:

<VisualState x:Name="CheckedNormal">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="NormalRectangle">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}"/>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimation Duration="0" To="{ThemeResource CheckBoxCheckedStrokeThickness}" Storyboard.TargetProperty="StrokeThickness" Storyboard.TargetName="NormalRectangle"/>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="NormalRectangle">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltTransparentBrush}"/>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="CheckGlyph"/>
    </Storyboard>
</VisualState>

Sample image:

enter image description here

Note also that you may need to edit also other visual states than the one mentioned above - it depends on your need.

like image 92
Romasz Avatar answered Dec 09 '25 13:12

Romasz