How do I measure the size of a TextBlock in WPF before it is rendered?
The call to UIElement.Measure(Size)
, takes as a parameter Size
. The second call UIElement.DesiredSize
returns whatever Size
you passed into the Measure
method.
I think this is the case because UIElement
(TextBlock
in this case) is NOT a child of any control (yet) and therefore DesiredSize
has no reason to be anything different.
I think it should be sufficient to call the UIElement.Measure(Size)
method and subsequently check the UIElement.DesiredSize
property. For more information, check the provided MSDN links.