Text Text Length + Crop

I use Bindings to populate a Listbox , with TextBlock s, etc.

Question:

How can I make sure that the text attached to the Text property of the TextBlock object has a certain length or that it is displayed cropped with a certain character length (for example, "some very very long t..." ) so that the text does not overflow the phone screen or its container?

+4
source share
2 answers

With the Mango SDK, there is a call to the TextTrimming property.

So this is xaml

 <TextBlock Text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" TextTrimming="WordEllipsis" Width="200" /> 

will create something like "aaaaaaa ....."

+2
source

Difficult! I forced myself to think that if the characters exceed, say, about 10, I'm going to add points to it. So I added this text event to the text box, and then made the code as follows:

 private void TestTextBox_TextChanged(object sender, TextChangedEventArgs e) { string temp = TestTextBox.Text; if (temp.Length > 10) { char[] charArray=temp.ToCharArray(); temp = new string(charArray, 0, 10); temp += "..."; } TestTextBox.Text = temp; } 
+1
source

Source: https://habr.com/ru/post/1490839/


All Articles