?
Solved

How to have more than one line of text in WPF label or text box

Posted on 2010-09-04
8
Medium Priority
?
2,637 Views
Last Modified: 2012-05-10
I am brand new to WPF controls. I need to create labels with more than one line of text and I have been having trouble figuring that out.

Thanks in advance for your help.
0
Comment
Question by:kyleboca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33605333
*Assuming your control is tall enough to display multiple lines...

You could do:

    this.label1.Content = "Line 1\r\nLine 2\r\nLine 3\r\n";

Or:

    this.label1.Content = "Line 1" + Environment.NewLine + "Line 2" + Environment.NewLine + "Line 3" + Environment.NewLine;
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33605338
VB.Net also has the old vbCrLf constant:

        Me.Label1.Content = "Line 1" & vbCrLf & "Line 2" & vbCrLf & "Line 3" & vbCrLf
0
 

Author Comment

by:kyleboca
ID: 33605356
I meant in the IDE property area next to content in the properties window.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33605469
Oh...hehe.  Try pressing Alt-Enter to go down to the next line.
0
 

Author Comment

by:kyleboca
ID: 33606620
alt+enter didn't work either.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33607528
Hmm...the WPF IDE works differently than the WinForms IDE...sorry about that!  =\

For Labels, you can select thim on the form then edit the XAML directly by adding a TextBlock as the Content and using :

       
            Line 1Line 2Line 3
       

Here is a picture:
WPF-MultiLine-Label-Using-TextBl.jpg
0
 

Author Comment

by:kyleboca
ID: 33610986
That looks like what I need to learn. Is there a way to "center" the multi-lines of text withing the label using xaml code?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 33611595
Just set the HorizonalContentAlignment and VerticalContentAlignment properties to Center.  This can be done thru the Properties Pane or you can enter it manually in the XAML:

       
            Line 1Line 2Line 3
       
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question