How do I measure the size of a TextBlock in WPF before it is rendered?

Posted by Scott Whitlock on Stack Overflow See other posts from Stack Overflow or by Scott Whitlock
Published on 2010-06-07T10:18:04Z Indexed on 2010/06/07 10:22 UTC
Read the original article Hit count: 199

Filed under:
|
|

I have a WPF DataTemplate with two TextBlock controls (stacked) and then some other elements underneath. Due to some complicated layout code, I need to know the height of the two TextBlock elements so that I can draw some fancy connector lines, and line up other controls, etc.

If I know the text that's going into the TextBlocks, and I know the font, etc., is there some way I can compute or measure the height of these TextBlocks without actually rendering them?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about textblock