WPF:汽车在TextBlock中截断文本 [英] WPF: Auto truncating text in TextBlock

查看:250
本文介绍了WPF:汽车在TextBlock中截断文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有600宽度和高度80的一个TextBlock在我的WPF 4.0应用程序。我想截断文本,并追加 ... 结尾,在运行时。能否请你建议我一些关于我应该如何处理呢?

I have a TextBlock of Width 600 and Height 80 in my WPF 4.0 application. I would like to truncate text and append ... at the end, at runtime. Could you please suggest me some about how should I approach it?

推荐答案

它是一个文本框或TextBlock的?

Is it a TextBox or TextBlock?

如果是TextBlock的,那么你可以使用:

If it is TextBlock, then you can use:

在C#

myTextBlock.TextTrimming = TextTrimming.CharacterEllipsis;

在XAML:

<TextBlock Name="myTextBlock" Margin="20" Background="LightGoldenrodYellow" 
  TextTrimming="WordEllipsis" 
  FontSize="14"
>

但是,如果它是一个文本框,然后按我的知识,你可以绑定一个 ValueConverter 的文本框和返回trancated文本(带有点:...)在文本框中,但保存完整的文成标记文本框属性。所以,你的原始文本不丢失。

But if it were a TextBox, then as per my knowledge, you can bind a ValueConverter to the textbox and return the trancated text(with dots : ...) into the text box but save the full text into the Tag property of the textbox. So that your original text is not lost.

但是,根据我所知,它是不适用的文字上的文本框微调,直到有特定的要求一个很好的做法。

But, as per my knowledge, it is not a good practice to apply text trimming on text boxes until there is a specific requirement.

这篇关于WPF:汽车在TextBlock中截断文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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