Search code examples
wpfsilverlightgridstackpanel

WPF Grid vs Stackpanel


For WPF/Silverlight layout, is it better to use a Grid with lots of rows and columns, or tons of Stackpanels?


Solution

  • You should use a Grid if you need things to line up horizontally and vertically. 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. In particular, have a look at the DockPanel. It's slightly more complex than a StackPanel, but its markup isn't as cluttered as the Grid. Here's a good article on the DockPanel:

    Using the DockPanel in Silverlight 2