Solved

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

Posted on 2010-09-04
8
2,266 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

856 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