I have a TextBox
and a Label. After clicking a button, I execute the following code:
label1.Content = textbox1.Text;
My question is, how do I enable text wrapping of the label? There may be too much text to display on one line, and I want it to automatically wrap to multiple lines if that is the case.
To wrap text in the label control, change the the template of label as follows:
You can put a TextBlock inside the label:
Instead of using a Label class, I would recommend using a TextBlock. This allows you to set the TextWrapping appropriately.
You can always do:
However, if all this "label" is for is to display text, use a
TextBlock
instead.I used this for retrieving data from MySql Database:
The
Label
control doesn't directly support text wrapping in WPF. You should use aTextBlock
instead. (Of course, you can place theTextBlock
inside of aLabel
control, if you wish.)Sample code:
We need to put some kind of control that can wrap text like textblock/textbox