- Usually you can set up the general layout with a Grid and use a few stackpanels here and there to do some specific stuff. Usually the performance is better with Grids and that Grids generally give you more flexibility.
- If you need things to line up both horizontally and vertically, you really should use a grid. But other than that, it really depends on the content you intend to display. Use a StackPanel to create a row or column of things when those things don't need to line up with anything else. However, don't limit yourself to those two options. You can use other containers depends on the content you intend to display.
- The Grid makes it possible
to size content to the space that contains it without explicitly providing a size for the container. The panel controls don't.
- Grid is more designer-friendly. With a Grid, there is no restriction on having multiple elements within a single Grid "cell", which allows a designer with free placement to have the same flexibility as a Canvas, but still have the automatic layout capabilities that Grid (and the other nicer layout controls like StackPanel and DockPanel) contains.
- StackPanel arranges each of its child elements to use minimal height (or minimal width if Orientation == Horizontal). StackPanel offers no properties to alter this behaviour. Grid on the other hand, unless indicated otherwise, will divide all available space evenly across each child (or rather row/column).
- In the most general sense, Grid is the most flexible, as it can have rows, columns, rowspans, column spans, controls can fill rows/columns, etc.. You can do a lot with these types of things.
How to choose WPF container controls
最新推荐文章于 2024-10-21 20:59:52 发布