I am new to WPF. The problem I'm trying to solve is how I can get the correct height at runtime.
In my application, I dynamically add Usercontrols to the Stackpanel in the code behind. Usercontrol contains several Texblocks. My Stackpanel is then used as Content for BookPage, and this BookPage is added to the book (http://wpfbookcontrol.codeplex.com/). The height of my stackpanel should not exceed a certain value.
I already realized that I can use Measure and Arrange to calculate ActualSize and Height Usercontrol:
itemsa.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
itemsa.Arrange(new Rect(0, 0, 400, itemsa.DesiredSize.Height));
At this point, Usercontrol is not added to the Stackpanel. 400 is a width that my user control should not exceed, but this happens because Textblock does not create automatic line breaks. When I show the Book, line breaks are created.
What should I do to solve this problem?
Thanks in advance.
source
share