简体   繁体   中英

How to change DataGridCheckBoxColumn checkbox check mark colour

I have a DataGridCheckBoxColumn in my DataGrid and it's foreColor and BackColor is Black by default in Windows8. While, it is fine in Windows7.

I am getting mad finding a solution about how to change the forecolor of the check mark.

Please help.....

Here is the complete native template for WPF checkboxes.

What your looking for is "GlyphColor" in the "Path.Stroke" in in the following code :

                <Path Visibility="Collapsed"
                  Width="7"
                  Height="7"
                  x:Name="CheckMark"
                  SnapsToDevicePixels="False"
                  StrokeThickness="2"
                  Data="M 0 0 L 7 7 M 0 7 L 7 0">
              <Path.Stroke>
                <SolidColorBrush Color="{DynamicResource GlyphColor}" />
              </Path.Stroke>
            </Path>
            <Path Visibility="Collapsed"
                  Width="7"
                  Height="7"
                  x:Name="InderminateMark"
                  SnapsToDevicePixels="False"
                  StrokeThickness="2"
                  Data="M 0 7 L 7 0">
              <Path.Stroke>
                <SolidColorBrush Color="{DynamicResource GlyphColor}" />
              </Path.Stroke>
            </Path>

From here you have at least two solutions :

1) "GlyphColor" is binded as a dynamic resources, that mean that you can change it and it will reflect the change of color immediatly for the mark in the checkbox. BUT, be carreful, it is possible that this resources is used for other controls, so it would change their color too.

2) The brute force solution would be to entirely override the CheckBox style by copy/paste of the above code into your project and to modify only the abovementionned property and replacing it by the color/resource you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM