I want to style the indeterminate state of a WPF checkbox. We have a treeview control with checkboxes, and we want the indeterminate state to represent that some descendants are checked and some are unchecked.
The solution I'm seeing everywhere is to override the default control template for a checkbox and do what I need to do.
I have two problems with that:
I can't find the control template for a normal Aero checkbox. This one: http://msdn.microsoft.com/en-us/library/ms752319.aspx looks goofy.
The control template I get from Expression Blend has that BulletChrome element in it, and I can't figure out what to do with that.
So does anyone know where to get a checkbox control template that looks "normal" or is there an easier way to just style the indeterminate state by itself?
I'm sure there's an easy way I'm just overlooking... Right?
You can use
CheckBox
styling from the classic theme located at:C:\Program Files (x86)\Microsoft Expression\Blend 4\SystemThemes\Wpf\classic.xaml
This implementation has a
Path
representing the checkbox mark calledCheckMarkPath
. I simply replaced thisPath
with a filledRectangle
to get these results:The below code is a sample check box with three state.
The best software to modify the existing look and feel of the controls is Expression Blend. If you want to change the existing look and feel and you have to modify the Control Template of the control.
Call me crazy, but I've actually reimplemented standard Aero checkbox in pure XAML. If you want to customize Aero checkbox, it's a good starting point. You can find other styles in my repository on GitHub (specific commit, in case files are moved).
BulletCommon.xaml (common resources for CheckBox and RadioButton)
CheckBox.xaml (resources for CheckBox)
Notes:
{xx:SystemBrush ControlText}
is a shortcut for{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}
. You can either use that shortcut or just find and replace with regex.RTL, animations, weird cases are not supported.
This style is slower than using
BulletChrome
which is heavily optimized.