Reformatting and Resizing Checkbox in WPF

Wally96333 61 Reputation points
2020-10-27T17:26:17.69+00:00

Hi all,

I am trying to resize and change the colors on a CheckBox control.

I have found the following code that almost works:

<StackPanel Height="34" Margin="8,0,0,0"
    Name="StackPanel_01" 
    Orientation="Horizontal" Background="#FFDCDC16">
                <Viewbox 
                 Height="{Binding Path=ActualHeight, ElementName=StackPanel_01}">
                    <CheckBox Background="#FF470707" Foreground="White" />
                </Viewbox>
</StackPanel>

I get a red box on initialization, which is good, but it turns white on hover.
I want it to stay red on hover.

Also, the check mark is black. I want it to be white, and stay white.

Any help with this would be appreciated.

THANKS!

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,756 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DaisyTian-1203 11,621 Reputation points
    2020-10-28T08:18:33.513+00:00

    You can edit the default style templete for the CheckBox to update the style depending on your needs.
    Step one: Open the Document Outline for the xaml
    Step two: Right click the CheckBox > Edit Templete >Edit a copy... in the popup window.
    Step Three: Update the style on your need as below shown:
    Red on hover :
    Go the Trigger <Trigger Property="IsMouseOver" Value="True"> and set the Value to Red for the Background property.
    Check mark to White :

    1. Update the Fill to white for <Path x:Name="optionMark" Fill="White" ...
    2. Update all <Setter Property="Fill" TargetName="optionMark" Value="#FF212121"/> to <Setter Property="Fill" TargetName="optionMark" Value="White"/> for triggers

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.