Reputation: 3204
I am trying to create a custom panel in wpf. Here the doubts I have,
Please help.
Upvotes: 4
Views: 681
Reputation: 3848
And don't forget to use InternalChildren instead of Children.
Upvotes: 0
Reputation: 34250
To implement your own panel, you need to implement MeasureOverride
and ArrangeOverride
. During layout, things are being figured out so the final values are not yet available. To get started, use the Size
argument passed to you in MeasureOverride
which is the available size. You could end up using more or less than this amount. That depends on the layout behavior of your panel. No matter what you do, you have to call Measure
on all your children and you can of course use that information in your calculations.
If you have some specific panel behavior you want to implement but don't want to handle a large number of special cases, then you can give your children all the space they request in the direction you are not stacking and let your children lay themselves out using sub-panels if necessary.
Upvotes: 2
Reputation: 50672
Whether or not you act on Horizontal and/or Vertical Alignment is up to you. It would be bad if a vertical StackPanel would consider the VerticalAlignment of a child.
You should call the Measure() method on each Child control. That will give you the desired size.
Upvotes: 3