Solved

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

Posted on 2010-09-04
8
2,193 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
  • 5
  • 3
8 Comments
 
LVL 85

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 85

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 85

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 85

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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

776 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