开发者

How do you vertically align check box of the checkbox properly?

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.Do开发者_如何转开发ck="Bottom" Name="pictureBox1"></Image>
</DockPanel>


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.


VerticalContentAlignment="Center" worked for me.

Note: VerticalAlignment="Center" does not work since it refers to the control itself, not the contents of the control.

Thanks to Antoine Meltzheim for this answer.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜