文字显示(TextTrim) [英] Text Displaying ( TextTrim )

查看:246
本文介绍了文字显示(TextTrim)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,
我正在使用WPF概念.我必须使用一个标签显示名称字段".
对于那个标签,我给的宽度...为70.
我的问题是,当Name的长度很大时,我就遇到了问题.
例如:如果名称类似于:Shiv Satya Narayanan Kumar ...

为此,我想这样显示...
示例:Shiv Satya ...

Hi and Good Morning,
I am Using WPF Concepts. I have to display Name Field by using one Label.
For that label I gave width... of 70.
My problem is, when the Name has huge lenght, then I am getting a problem.
For Example: If the Name is like : Shiv Satya Narayanan Kumar...

For that I want to show like this ...
Example : Shiv Satya...

推荐答案

只需使用Substring 表示想要显示的字符.
Just use Substring for as many characters you want to display.
if(field.Tostring().Length > 10)
Lable.Text = Name.Substring(0,10) + "...";


在上述答案的基础上,您可以保留标签控件(具有适当的属性值,例如Width = 70)并将其内容设置为 TextBlock ,即:
Building on the above answer you could keep your label control (with its appropriate property values, like Width=70) and set its content to a TextBlock, i.e:
<Label Width="70">
  <TextBlock Text="Shiv Satya Narayanan Kumar" TextTrimming="CharacterEllipsis"/>
</Label>


使用TextBlock代替label并设置

TextTrimming ="CharacterEllipsis"
Use TextBlock instead of label and set

TextTrimming="CharacterEllipsis"


这篇关于文字显示(TextTrim)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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