sudarsanyes
sudarsanyes

Reputation: 3204

Considering HorizontalAlignment and VerticalAlignment while creating a custom panel

I am trying to create a custom panel in wpf. Here the doubts I have,

Please help.

Upvotes: 4

Views: 681

Answers (3)

Marat Khasanov
Marat Khasanov

Reputation: 3848

  • You don't need to consider HorizontalAlignment and VerticalAlignment. These properties are used internally by FrameworkElement and take effect automatically.
  • The single argument of ArrangeOverride will give you a size, which parent allowed for your panel. You must arrange children within this area. If you mean that "Auto" is a size to place all panel's children, you must compute and return it from MeasureOverride.

And don't forget to use InternalChildren instead of Children.

Upvotes: 0

Rick Sladkey
Rick Sladkey

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

Emond
Emond

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

Related Questions