tags:

views:

47

answers:

2

When you add a checkbox to a window and center it vertically, superficially it seems it is OK. However when you increase the padding you notice something odd -- the label part of the checkbox is centered indeed, but the check box remains in the left-top corner. So with enough padding you will get such result

[ ]
     this is my checkbox

So, question is -- how to align check box of the checkbox properly?

Edits

<DockPanel>
      <StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
        <CheckBox Name="XSwitchCheckBox" 
                  VerticalContentAlignment="Center" 
                  VerticalAlignment="Center" 
                  Padding="4">X-axis switch</CheckBox>
    </StackPanel>
    <Image DockPanel.Dock="Bottom" Name="pictureBox1"></Image>
</DockPanel>
+1  A: 

I am not able to reproduce your issue. Are you setting the All property of the Padding property or are you setting the Left property? You may also want to try adjusting the Margin property.

With a Left Padding on my small form my checkbox looks like:

   [] checkbo
      x1

You may also try, Padding="2,0,0,0" in which you should see the entire checkbox move. I believe in your code you may be setting your padding to a value greater than the space available.

Hopefully this will help you clear this up.

Michael Eakins
I would like to center it vertically so changing left part of padding does not change a thing in vertical alignment. And I am setting all parts of padding. Setting margin also does not affect the problem, because margin changes the space outside the widget.
macias
Changing Vertical Padding should not affect the text alignment in relation to the check portion of the checkbox alignment.
Michael Eakins
I know, but it does.
macias
+1  A: 

The checkbox layout is done using the BulletDecorator Class. It looks like the padding you are setting is getting applied to the bullet child, not to a container which contains the bullet and the child.

Douglas
It seems more like a bug, because in such case the check box is fixed really.
macias
Yes, it's not the behaviour I would have expected.
Douglas