[英]XAML TextBlock Binding with "..." at the end if text is too long
I have an ItemsControl with TextBlock inside.我有一个里面有 TextBlock 的 ItemsControl。 The TextBlock's text is Binded but if it is too long, it is truncated.
TextBlock 的文本已绑定,但如果它太长,则会被截断。 I have already calculated the maximum character limit (20) and I would like that if it does not exceed them it is binded regularly, otherwise it is truncated but with "..." at the end.
我已经计算了最大字符限制 (20),我希望如果它不超过它们,则它会定期绑定,否则会被截断,但最后会带有“...”。 I think I know how to do in codebehind, but I would like to do it exclusively from XAML using (I think) the Style.
我想我知道如何在代码隐藏中做,但我想使用(我认为)样式从 XAML 中完成它。
If you set TextTrimming="CharacterEllipsis"
on your TextBlock
that will give you the behavior you need automatically.如果您在
TextBlock
上设置TextTrimming="CharacterEllipsis"
,它将自动为您提供所需的行为。
If you need to enforce that 20 character limit, you can set a MaxWidth
on your TextBlock
to a value that gives you the width you need and TextTrimming
will do the rest.如果您需要强制执行 20 个字符的限制,您可以将
TextBlock
上的MaxWidth
设置为一个值,该值可为您提供所需的宽度, TextTrimming
将完成剩下的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.