TextClipping is useful. TextBlock control is a basic control in WPF and is very useful. The reason for this is that it allows you to put text on the screen but in a simpler way.

TextBlock works well for multiline strings and comes with many advantages. It’s an extension used by Mac computers for those strings of text. Selecting a string of text and dragging it over to the desktop or somewhere else on a Mac computer, the computer then converts it automatically into a .textClipping file. The file can be dragged to any text box to copy the exact text and also it’s formatting.

Trimming Text

A handy feature of WPF is the means to tell TextBlock to cut short its text to ellipses. They’re great for omitting words and phrases and indicating unfinished thoughts if there isn’t enough room for the text. When text in a TextBlock doesn’t fit the available space, the text is then trimmed or clipped against the boundaries of the available space by default.

Ellipses look like this …’  This is useful in data binding when you don’t know what the text will be.

Data binding in WPF or Windows Presentation Foundation provides an easy way for apps to interact with data.

ContentControl and items control have functionality built in to ensure flexible styling of collections of data items. If you display a string that is way too long for a TextBlock it keeps writing past the edge of the TextBlock. If the text doesn’t fit into the space provided, how does one do this in Silverlight?

This ability to truncate text to ellipses is missing from Silverlight. Microsoft Silverlight is a free web browser plug-in. It works on all the main operating systems and all the leading browsers such as Chrome, Firefox, Google, Internet Explorer and Safari.

WPF and Silverlight trim the text displayed by a TextBlock.I took a different approach this time and made the Control itself a ContentControl.

A few times I’ve written workarounds but haven’t been happy with the results. I usually derive the new control from TextBlock but the problem is that by doing this, I’ve had a hard time getting the TextBlock to layout its text so that I can re-measure it in time and then adjust it. Everything just gets messed up.

This time I decided to do things a little bit differently and made the Control a ContentControl that hosts a TextBlock and seen that this works much better.

I decided to take a different approach and the Control was made by me. ContentControl in WPF is a base class that provides functionality to WPF Controls. I can change the text and re-layout from within the Measure override of the ContentControl.

There’s a lot of room for improvement. I’m merely shortening the text one character at a time and confident that that could be improved. I only have the equivalent of TextTrimming=CharacterEllipses as opposed to TextTrimming=WordEllipses, but I think that I shouldn’t have trouble adding that as well.

0 Shares:
You May Also Like
Timesheet PDF
Read More

Timesheet PDF

I love trying apps and other online tools to help me with my day-to-day tasks and time tracking…