WPF Grid vs Stackpanel

20,505

Solution 1

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

Solution 2

The container you use should be based on the content and not whether one approach is better than another. 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.

Solution 3

I don't think Grid is a better idea.

for example , if you want to insert a row to existing Grid layout document (in the middle)

there exising row is 1,2,3,4 , then the requirement is insert new row between 1 and 2.

then you had to change 2,3,4 to 3,4,5 (find all tag an change....)

think about if one row have 3 - 5 columns... it's a dirty job to reorder all digital.!!!

Solution 4

I think the Grid is a better idea. I usually set up the general layout with a Grid and use a few stackpanels here and there to do some specific stuff. I also have a feeling that performance is better with Grids and that Grids generally give you more flexibility.

Share:
20,505
NotDan
Author by

NotDan

Bootstrap Themes Make #regions suck less If you have to deal with Visual Studio regions, use this tool to regain some sanity. Learn the states and capitals game Learn the U.S. states and capitals.

Updated on February 24, 2020

Comments

  • NotDan
    NotDan about 4 years

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