tags:

views:

2950

answers:

1

How can I add a newline in the text of a label in WPF?

eg.:

<Label>Lorem 
  ipsum</Label>
+14  A: 
<Label><TextBlock>Lorem<LineBreak/>ipsum</TextBlock></Label>

You need to use TextBlock because TextBlock accepts as children a collection of Inline objects. So you are giving the TextBlock element three Inline items: Run Text="Lorem", LineBreak, and Run Text="ipsum".

You can't do: <Label>Lorem<LineBreak/>ipsum</Label> because Label accepts one Content child element.

Edit: Also, not sure exactly what your use case is but notice I placed a TextBlock inside your Label element. Is it repetitive? Not really, depending on your need. Here's a good article on the differences between the two elements: Difference between Label and TextBlock

siz
yea sorry I missed that when I googled it. nice catch +1
jmein