How can I align a CheckBox with its content?

DeveloperDan picture DeveloperDan · Aug 29, 2011 · Viewed 40k times · Source

The look of a WPF CheckBox misaligns the check portion with the label (content) portion. The check stays slightly above the content as shown here:

enter image description here

The XAML looks like this:

<CheckBox Content="Poorly aligned CheckBox" Margin="9"/>

The CheckBox is inside a Grid cell. Is there a simple way to make the content and check portions of a XAML CheckBox align vertically? I've tried various combinations of properties with no luck. I saw a similar question here but the answer is way too complex.

Thanks in advance.

EDIT: The problem was caused by the Window FontSize which I set to 14. To re-create the problem set the CheckBox FontSize to 14 (or more). My program is viewed at a distance by factory workers so I allow the Window FontSize to be increased or decreased by the user.

Answer

Majid picture Majid · Sep 23, 2013

I know it's too late, but here is a better solution, without setting margins. Margins should be set differently for different heights of TextBlock or Checkbox.

<CheckBox VerticalAlignment="Center" VerticalContentAlignment="Center">
    <TextBlock Text="Well aligned Checkbox" VerticalAlignment="Center" />
</CheckBox>

Update:

It's worth checking out @nmarler's comment below.