Silverlight中的字符串对齐方式 [英] string alignment in Silverlight

查看:53
本文介绍了Silverlight中的字符串对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

考虑以下示例。



姓名:Richard

姓:Mark

职业:开发人员



我真的不考虑右边的值(例如:Richard,Mark,..)

我的要求更像是以下

图1

http://snag.gy/fkZqK.jpg [ ^ ]



我有尝试设置如下所示的固定宽度



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





但是这总是显示如下所示的显示

http://snag.gy/ Y7IQu.jpg [ ^ ]


Silverlight中的


您可以看到文本没有在一条直线上正确对齐。



如何对齐上面的内容以便它显示为Silverlight中的图1(上图)。



我也试过过标签(\t)。但是也没有给我我需要的东西。



谢谢你的时间..

解决方案

< blockquote>你只是在格式错误的顺序。



尝试使用

字符串。格式(名称:{0} \\\
Last:{1} \\\
Occupation:{2},Mohan,PrasathSJ,Praba);


如果您在wordwrapped控件中显示此文本,则可以移动到下一行。

设置控件的最小宽度以容纳此字符串。


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
Diagram1
http://snag.gy/fkZqK.jpg[^]

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
http://snag.gy/Y7IQu.jpg[^]

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..

解决方案

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");


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.


这篇关于Silverlight中的字符串对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆