Click here to Skip to main content
15,846,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,
Consider a following example.

Name : Richard
Last Name : Mark
Occupation: Developer

I really dont you to consider the values on right hand side(eg:Richard, Mark,..)
and my requirement is more like the following

I have tried setting a fixed width like the below

string.Format("{0,-10}: Name\n{1,-10}: Last\n{2,-10}: Last\n", "Mohan", "PrasathSJ","Praba");

But this always shows the display like below[^]

in Silverlight.
You could see that the text doesnot get aligned properly in a straight line.

How the above can be aligned so that it displays like the Diagram 1(above) in silverlight.

I have tried with tags("\t") also. But too didn't give me what exactly I need.

Thank you for your time..
Updated 19-Feb-14 21:19pm

you've simply got things in the wrong order in the format.

Try using
string.Format("Name :{0}\nLast :{1}\nOccupation :{2}", "Mohan", "PrasathSJ","Praba");
Share this answer
Prasaad SJ 20-Feb-14 2:36am    
Hi.. Thanks for your response.
I am actually following the below

I am setting a fixed width here. This works fine in Command Prompt but not looking good(as shown in diagram2) in Silver light. I usually beleive that the Cmd prompt took the whole pixel but Window tries to decrease the size of letter based on the letter( You can see that in the link 2 that I included)
NeverJustHere 20-Feb-14 7:03am    
OK, I understand better now.
You need to change the font to a fixed width font. This will be a property on whatever text control you are using.

The console uses a fixed width font. A fixed width font has each letter taking the exact same width.

As an alternatice, in Silverlight you could use 6 different text controls, and align them as you want. Then each of the controls gets a different part of the text.
Prasaad SJ 25-Feb-14 21:04pm    
You got it.. How could I achieve the fixed width font in Silverlight.. ?
In case you are displaying this text in a wordwrapped control, this could move to the next line.
Set the minimum width of the control to accommodate this string.
Share this answer
Prasaad SJ 20-Feb-14 2:37am    
Hi.. Abinav I did set the width of the each string using the below code
string.Format("{0,-10}: Name\n{1,-10}: Last\n{2,-10}: Last\n", "Mohan", "PrasathSJ","Praba");

But still then it looks not aligned in the window.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900