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?
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;
来源:https://stackoverflow.com/questions/10556019/how-to-calculate-the-textbock-height-and-width-in-on-load-if-i-create-textblock