Johnson
Johnson

Reputation: 55

Get ActualHeight from control after it's text has been bound

I am trying to get the ActualHeight of a TextBlock after it's text has been changed. This text may change multiple times on the same page, which means the Loaded method on my page, is only fired once..

Getting the value in the Page Loaded method works fine, but only for the first time. If i change the text of my textblock I am having trouble getting the new actualheight.

What I have tried so far:

I was thinking if there is a way to reload the Textblock everytime I set it's value, so that I can get the actualheight through the TextBlock's Loaded method. But there doesn't seem to be a .Refresh() method for this in Windows Phone App's.

Does anyone have any idea's as to what I could do to get the actualheight including linebreaks, after I've set it's text to a new value?

Upvotes: 0

Views: 79

Answers (1)

Daniel Lane
Daniel Lane

Reputation: 2593

Subscribe to the SizeChanged event. It's for precisely the use case you have presented.

MSDN Documentation - TextBlock Events, SizeChanged Event

That event will fire whenever the ActualHeight or ActualWidth properties change for the TextBlock element. As wpf controls inherit from the FrameworkElement base class, WPF controls all have access to this property.

Upvotes: 1

Related Questions