Custom Layout
Although WPF supplies a flexible set of layout elements, you might decide that none of them suits your requirements. Fortunately, the layout system is extensible, and it is fairly straightforward to implement your own custom panel. To write a panel, you need to understand how the layout system works.
Layout occurs in two phases: measure and arrange. Your custom panel will first be asked how much space it would like to have—that's the measure phase. The panel should measure each of its children to find out how much space they require, and use this information to calculate how much space the panel needs in total.
Of course, you can't always get what you want. If your panel's
measure phase decides it needs an area twice the size of the screen, it
won't get that unless its parent happens to be a ScrollViewer. Moreover, even when there is
enough space on-screen, your panel's parent could still choose not to
give it to you. For example, if your custom panel is nested inside a
Grid, the Grid may have been set up with a hardcoded
width for the column your panel occupies, in which case that's the width
you'll get regardless of what you asked for during the measure
phase.
It is only in the "arrange" phase that we find out how much space we have. During this phase, we must decide where to put all of our children as best we can in the space available.
Tip
You might be wondering why the layout system bothers with the measure phase when the amount of space we get during the arrange phase ...