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?
+5
A:
Is it a TextBox or TextBlock?
If it is TextBlock, then you can use:
In C#:
myTextBlock.TextTrimming = TextTrimming.CharacterEllipsis;
OR
In XAML:
<TextBlock Name="myTextBlock" Margin="20" Background="LightGoldenrodYellow"
TextTrimming="WordEllipsis"
FontSize="14"
>
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.
Siva Gopal
2010-09-19 12:09:35
its a TextBlock
Ruby
2010-09-19 13:10:28
Is there a way I can wrap the text without setting width of the TextBlock?
Ruby
2010-09-19 13:17:36
The wrapping of text inside a control is based on the width of that control. If you want to implement the wrapping irrespective of width,then ValueConverter is the easiest option you can pick, as per my knowledge.
Siva Gopal
2010-09-19 13:48:50