#329 – Principles of Layout in WPF
June 27, 2011 2 Comments
WPF uses a flow-based layout model by default, where child elements are placed in a container and explicitly positioned based on their content. This is as opposed to coordinate-based layout, where controls are given specific sizes and positions.
Parent containers (deriving from Panel) are responsible for figuring out both the size and position of all of their child controls.
In general, we following the following layout principles in WPF:
- Don’t give controls a specific size, but let them size to fit their content
- Don’t give controls a specific location, but let the parent container position them
- Layout containers can be nested inside of other layout containers
Pingback: #383 – The Problems with Coordinate-Based Layout « 2,000 Things You Should Know About WPF
Pingback: #384 – The Benefits of Flow-Based Layout « 2,000 Things You Should Know About WPF