开发者

New line in the text for a CheckBox using WPF?

How di I make a newline in the text for a checkbox? I've tried \n but it didn't wor开发者_JAVA技巧k?

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>


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


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>


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜