Reputation: 632
In WinForm we can set BackColor of a CheckBox
How do I do this in WPF? I try
<CheckBox Content="CheckBox" Background="Red"/>
but this only changes the rectangle border color
I also try
<CheckBox>
<TextBlock Text="CheckBox" Background="Red"/>
</CheckBox>
but this only changes the text background color, not including the rectangle
=======
Thank you all for the solutions. I think the simplest way works for me :)
Upvotes: 8
Views: 9523
Reputation: 235
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox FlowDirection="RightToLeft" background="Red"
IsChecked="False" />
<Border Grid.Column="1"
Margin="20 0 0 0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="LightGray">
<TextBlock HorizontalAlignment="Left"
Foreground="Black"
Style="{StaticResource RegularTextblock}"
Text="Checkbox1" />
</Border>
</Grid>
Upvotes: 4
Reputation: 3004
You are asking for little too much. Using Blend I made created a relevant style for the CheckBox
.
The code was too big. So SO did not allow to display. Here is the pastie link
For the Background
there is a grid markGrid
. I added a Background
and a TemplateBinding
to force the CheckBox
to change the colour. The drawback is the Path colour will be visible very faintly if the background is dark.
Upvotes: 1
Reputation: 7467
If you experiment a little with panels you get there:
<Grid Background="Red" HorizontalAlignment="Left">
<CheckBox Content="test" />
</Grid>
is pretty close to what you want. Tried it myself ;-)
Upvotes: 11