Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline Text in a WPF Button

Tags:

c#

multiline

wpf

How do I get multi-line text on a WPF Button using only C#? I have seen examples of using <LineBreak/> in XAML, but my buttons are created completely programmatically in C#. The number and labels on the buttons correspond to values in the domain model, so I don't think I can use XAML to specify this.

I have tried the naive approach below, but it does not work.

Button b = new Button();
b.Content = "Two\nLines";

or

b.Content = "Two\r\nLines";

In either case, all i see is the first line ("Two") of the text.

like image 647
Paul Avatar asked Sep 19 '09 19:09

Paul


2 Answers

OR in XAML directly:

<Button>
   <TextBlock>Two<LineBreak/>Lines</TextBlock>  
</Button>
like image 191
Sergey Malyan Avatar answered Nov 05 '22 08:11

Sergey Malyan


I prefer this way:

<Button Width="100">
  <TextBlock TextWrapping="Wrap">This is a fairly long button label</TextBlock>
</Button>

it worked for me.

like image 59
MelloG Avatar answered Nov 05 '22 08:11

MelloG