9
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?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Kishore Kumar
  • 21,449
  • 13
  • 81
  • 113
  • WPF had methods like arrange/measure, you gave available space and got dimensions as a result. Isn't there something similar in Jupiter? – Filip Skakun May 12 '12 at 00:30

3 Answers3

10

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

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
1

Can also do this via

UpdateLayout();
testBlock.ActualWidth

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

themullet
  • 833
  • 8
  • 14
0
TextBlock tbl = new TextBlock();
tbl.Text = "Kishore";

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

double x = tbl.ActualHeight;
guyr
  • 1