Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I can't access the Height of TextBlock control when It's Height is "Auto".

C#
TextBlock t = new TextBlock()
{
    Width = 280,
    TextWrapping = System.Windows.TextWrapping.Wrap,
    FontSize = 12,
    Tag = foundClosureDay.CurrentDate,
    ToolTip = Persians.JulianToHijri(foundClosureDay.CurrentDate).DateToString
};
t.Text = "bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla ";

double height = t.Height;

height = t.ActualHeight;



Please help me, both t.Height and t.ActualHeight don't work.
Posted
Updated 11-Aug-20 1:05am
v2

The reason this doesn't work is because ActualHeight is zero until it completes the Loaded > Measured > Arranged > Rendered cycle. In order to get ActualHeight, you need to subscribe to the SizeChanged event to get the actual height when it's set. Basically, in your code, you are getting the value too early.
 
Share this answer
 
Comments
mariazingzing 18-Apr-11 4:52am    
Thanks
If Height is Auto, you have to use the ActualHeight. The only thing to keep in mind is, it works only after the control is rendered. So, if you try to use ActualHeight during Load event, it won't work.
 
Share this answer
 
Comments
mariazingzing 16-Apr-11 0:10am    
ActualHeight does not work.
Sorry! not my Answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900