Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line in the text for a CheckBox using WPF?

Tags:

c#

checkbox

wpf

How di I make a newline in the text for a checkbox? I've 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>
like image 853
Peter Rasmussen Avatar asked May 20 '11 14:05

Peter Rasmussen


3 Answers

    <CheckBox Content="Stuff on line1&#x0a;Stuff on line 2" />
like image 124
schummbo Avatar answered Nov 11 '22 04:11

schummbo


You should not use a StackPanel for line-breaks, TextBlocks can do that easily:

<CheckBox>
    <TextBlock>
        <Run Text="Line 1"/>
        <LineBreak/>
        <Run Text="Line 2"/>
    </TextBlock>
</CheckBox>
like image 23
H.B. Avatar answered Nov 11 '22 04:11

H.B.


In WPF, you can put any control almost anywhere. So you could try this:

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

Also, you need to remove the Height property from your checkbox. Of course only one line gets displayed if the height doesn't permit displaying more.

In WPF, in most cases you don't need to (nor should) specify absolute dimensions for your controls. They can adjust automatically quite well.

like image 29
Botz3000 Avatar answered Nov 11 '22 03:11

Botz3000