For a customer project I'm working on currently, I needed a more precise WPF container. I need to place controls on a position on the panel, where the center of the control has a meaning to the user. This means that the positioning has to take into account the height of the control.
The WPF Canvas implementation has the attached property Canvas.Top, which makes sure the outer top of the control is at a given position. Of course this doesn't take into account the fact that a control has a Height.
I then looked into creating a custom panel, and expected it to be tough. It turned out to be quite simple.
You start out by overriding MeasureOverride, in which a panel measures its children and itself. Next is ArrangeOverride, in which the panel arranges the children in the rectangle passed as the first parameter (finalSize). Arranging children is then quite easy, first you retrieve the desired center position (attached property), then you subtract the Height/2 of the control, and use that to call child.Arrange.
dinsdag 22 juni 2010
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten