#399 – WrapPanel Will Change Layout of its Children as its Size Changes

We saw that a WrapPanel will lay out its children either horizontally, filling a row at a time, or vertically, filling a column at a time.

The WrapPanel will also re-calculate the layout of its children whenever the size of the WrapPanel itself changes.  This will cause the location of the child elements to change.

Assume that we have the following WrapPanel whose Orientation property is set to Horizontal.  It lays out its child elements left to right on the first row and then starts a second row when the first row fills.

If we make the WrapPanel wider by making the Window wider, we can fit more child elements onto each row.

Similarly, if we make the WrapPanel narrower, we’ll fit fewer elements onto each row and so we’ll end up with more rows.