New line in text for CheckBox using WPF?

How can I make a new line in the text for a checkbox? I tried \ n but it didn't work?

EDIT: this is my CheckBox

<CheckBox xml:space="preserve" Height="16" HorizontalAlignment="Left" Margin="360,46,0,0" Name="ShowOldRegistrations" VerticalAlignment="Top" Checked="ShowOldRegistrations_Checked" Unchecked="ShowOldRegistrations_UnChecked"> <StackPanel Height="42" Width="108"> <TextBlock>Line1</TextBlock> <TextBlock>Line2</TextBlock> </StackPanel> </CheckBox> 
+4
source share
3 answers

In WPF, you can use any control almost anywhere. So you can try the following:

 <CheckBox> <StackPanel> <TextBlock>foo</TextBlock> <TextBlock>bar</TextBlock> </StackPanel> </CheckBox> 

In addition, you need to remove the Height property from your checkbox. Of course, only one line is displayed if the height does not allow more to be displayed.

In WPF, in most cases, you do not (and should not) specify absolute sizes for your controls. They can be automatically configured.

+2
source
  <CheckBox Content="Stuff on line1&#x0a;Stuff on line 2" /> 
+8
source

You should not use the StackPanel for line breaks, TextBlocks can do this easily:

 <CheckBox> <TextBlock> <Run Text="Line 1"/> <LineBreak/> <Run Text="Line 2"/> </TextBlock> </CheckBox> 
+4
source

All Articles