Silverlight / WPF - how to break new line in label at a run time in wpf

Asked By Sudhansu shekhar on 17-Apr-12 06:11 AM

hello frnds ,

 how to break new line in label at a run time in wpf.....
i want to show my data in label as a multi line.
Please reply asap.
Somesh Yadav replied to Sudhansu shekhar on 17-Apr-12 06:19 AM
<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 http://joshsmithonwpf.wordpress.com/2007/07/04/differences-between-label-and-textblock/

Jitendra Faye replied to Sudhansu shekhar on 17-Apr-12 09:37 AM
uSE <LineBreak />

TRY LIKE THIS-



<Label><TextBlock>SIMPLETEXT<LineBreak/>AGSDJG</TextBlock></Label>