Issue
I have an GridItem that has a fixed Height/Width.
It contains a textblock that has the max line set.
How can I determine if this text is trimmed?
I want to add special functionality if it is trimmed.
Solution
We ended up making a static function
// Ensure block does not have MAXLINES or text trimming set prior to checking
public static bool IsTruncated(TextBlock block, int maxLines)
{
if (block == null)
{
throw new ArgumentNullException("block");
}
//the cut-off height is the height at which text will be cut off in the UI
var cutOffHeight = maxLines * block.LineHeight;
//determine whether the actual height of the TextBlock is greater than the cut-off height
return block.ActualHeight > cutOffHeight;
}
The trick is to make sure that Maxlines and text trimming is NOT set on the Textblock prior to running this function. After this function returns, that is when the Maxlines is set. In my case I just saved the returned Boolean in a containing object so I knew it was longer. Then I set maxlines and another button to see the extended content based on that Boolean.
Answered By – Frank Sposaro
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0