WPF Runtime Height

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.

+3
source share
3 answers

Not sure what you are looking for, but with MaxHeight you have the ability to limit the growth of the control.

In general, there is no need to redefine Measure and Arrange, the Layout system is very efficient and offers you a lot of container control elements that provide specific layout behavior.

0
source

MaxHeight ?

ActualWidth ActualHeight .

, ? , GridRows - .

0

, , . Panel, MeasureOverride ArrangeOverride, , . , , , .

, , .

0

All Articles