Solved

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

Posted on 2010-09-04
8
2,092 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
Comment Utility
*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
Comment Utility
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
Comment Utility
I meant in the IDE property area next to content in the properties window.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Oh...hehe.  Try pressing Alt-Enter to go down to the next line.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:kyleboca
Comment Utility
alt+enter didn't work either.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now