Another simple and useful layout panel in WPF is a StackPanel. It works almost like a WrapPanel, but with a difference that it can't wrap the child elements to a new line. All items added inside it either get placed in horizontal or vertical stacks.
The StackPanel measures its children using either native or relative sizing, keeping the arrangement pass simple by laying out the items in order.
However, the Grid uses complex combinations of child elements when proportional sizing or auto sizing is used. Thus, it makes the Grid layout have a slow to medium performance for the measure pass and the arrangement pass to execute.
Therefore, wherever possible, the StackPanel preferable to over the Grid panel to reduce the rendering overhead.
However, the Grid uses complex combinations of child elements when proportional sizing or auto sizing is used. Thus, it makes the Grid layout have a slow to medium performance for the measure pass and the arrangement pass to execute.
Therefore, wherever possible, the StackPanel preferable to over the Grid panel to reduce the rendering overhead.
In this recipe, we will learn how the StackPanel works, by using a very simple example.