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

3

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?

Encephalomyelitis answered 11/5, 2012 at 17:32 Comment(1)
WPF had methods like arrange/measure, you gave available space and got dimensions as a result. Isn't there something similar in Jupiter?Serendipity
S
10

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

Serendipity answered 12/5, 2012 at 2:14 Comment(1)
First, Measure is called, then Arrange.Raynell
P
1

Can also do this via

UpdateLayout();
testBlock.ActualWidth

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

Prindle answered 16/9, 2015 at 13:0 Comment(0)
B
0
TextBlock tbl = new TextBlock();
tbl.Text = "Kishore";

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

double x = tbl.ActualHeight;
Beggs answered 17/10, 2014 at 2:27 Comment(1)
A little explanation might help.Hospice

© 2022 - 2024 — McMap. All rights reserved.