Question

TextBlock tbl= new TextBlock();
tbl.text="Kishore";

double x=tbl.ActualHeight;
double y=tbl.ActualWidth;

If i execute the code from the loaded event in Metro - winRT will return 0 for both.

How can I get the ActualWidth in the Loaded or SizeChanged event?

Was it helpful?

Solution

Call Measure() then Arrange() and then ActualWidth and ActualHeight will be updated.

OTHER TIPS

Can also do this via

UpdateLayout();
testBlock.ActualWidth

This could be useful when calculating multiple objects heights and widths.

TextBlock tbl = new TextBlock();
tbl.Text = "Kishore";

tbl.Measure(new Size(0, 0));

double x = tbl.ActualHeight;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top