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.
try use this
Often you cannot replace a
Label
with aTextBlock
as you want to the use theTarget
property (which sets focus to the targeted control when using the keyboard e.g. ALT+C in the sample code below), as that's all aLabel
really offers over aTextBlock
.However, a
Label
uses aTextBlock
to render text (if a string is placed in theContent
property, which it typically is); therefore, you can add a style forTextBlock
inside theLabel
like so:This way you get to keep the functionality of a
Label
whilst also being able to wrap the text.I used the following code.