I need to know the size of my Textblock before it is rendered. I have gone through this link but its not working (may be I am doing something wrong). My Textblock is binded to the property in a ViewModel and in code behind I am monitoring the text changed event.
XAML:
<TextBlock Text="{Binding Path=MyProperty, NotifyOnTargetUpdated=True}"
TargetUpdated="OnTargetUpdated"/>
and code behind:
private void OnTargetUpdated(object sender, DataTransferEventArgs e)
{
var tb = sender as TextBlock;
var text = tb .Text; // here I can see updated Text
var size = tb.DesiredSize; // here DesireSize value is 0
tb.Measure(new Size(Double.PositiveInfinity,
Double.PositiveInfinity));
tb.Arrange(new Rect(tb.DesiredSize));
var width = tb.ActualWidth; // here actual width is coming 0
}