Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to calculate the textbock height and width in on load if i create textblock from code?

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?

like image 917
Kishore Kumar Avatar asked May 11 '12 17:05

Kishore Kumar


2 Answers

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

like image 143
Filip Skakun Avatar answered Sep 20 '22 22:09

Filip Skakun


Can also do this via

UpdateLayout();
testBlock.ActualWidth

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

like image 30
themullet Avatar answered Sep 21 '22 22:09

themullet