Jarvis
Jarvis

Reputation: 691

How can I increase the space between the checkbox and the associated text?

I'm using WPF, and I have a CheckBox element with associated text/content. I've changed the FlowDirection to be RightToLeft so that the checkbox appears to the right of the text. But it appears very close to the text. I'd like to increase the spacing between the text and the checkbox, but of course the Margin option changes the outside margins of the whole control. Thanks for any ideas.

<CheckBox IsChecked="True" HorizontalAlignment="Left" FlowDirection="RightToLeft">Activate</CheckBox>

Upvotes: 11

Views: 9936

Answers (3)

mausinc
mausinc

Reputation: 537

By default xaml makes the checkbox a void item. Change the <Checkbox /> to <CheckBox></CheckBox> and inside the tag add a textblock to add the content. Add padding to change the alignment with the box.

<CheckBox x:Name="ChkExcel" Grid.Column="0" Grid.Row="3" Margin="0 3 0 3">
          <TextBlock Padding="10 2 0 0">Microsoft Office Excel</TextBlock>
        </CheckBox>

Upvotes: 0

Oliver Hanappi
Oliver Hanappi

Reputation: 12336

This should work too:

<CheckBox>
    <TextBlock Margin="10 0 0 0">Activate</TextBlock>
</CheckBox>

Upvotes: 11

brunnerh
brunnerh

Reputation: 184286

Padding, probably.

Box Model

See also: Aligment, Margins and Padding Overview

Upvotes: 18

Related Questions