Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a line break in a label

Tags:

wpf

c#-4.0

How to add a line break in a label. I have a label in which i m adding a text which will result in this display

A B C i have done this in WinForms c# with Environment.NewLine but this is not working in WPF application

Can some one tell me how can i add line break in label?

Am doing this from code behind and not XAML

like image 849
DDR Avatar asked Nov 30 '22 13:11

DDR


1 Answers

If you're fine with using TextBlock instead of Label (you should be!), then you can do it like this:

<TextBlock>
    <Run Text="First Line"/>
    <LineBreak/>
    <Run Text="Second Line"/>
</TextBlock>

You can do this from code behind as well (not sure why you would want to though):

tb.Inlines.Add(new Run("First Line"));
tb.Inlines.Add(new LineBreak());
tb.Inlines.Add(new Run("Second Line"));
like image 183
Isak Savo Avatar answered Dec 11 '22 14:12

Isak Savo