views:

203

answers:

4

Seen various examples of WPF applications I've seen the use of the Grid control for almost anything, even simplest things with only 1 column or row.

Also, the WPF templates start with an empty grid.

For me, using StackPanel or DockPanel is less verbose and are better for maintenance (think adding a row later and having to add +1 to all the other rows)

Why is Grid better or what I am missing?

+1  A: 

not missing anything. I have quite a lot of grids in my application(s), but not necessarily as top level element and definitely not to the extend you describe.

Could be many people just dont realize that they can remove the initial grid, and instead they put their own control into the grid.

TomTom
+2  A: 

I think part of the reason for Grid being the default element is that it's (slightly) 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.

Reed Copsey
+1  A: 

I have found that for more elaborate windows, it is easier to break it down into functional areas that are fairly independent (movement and size wise) of the others. Grids allow those areas to coexist in a single panel, and allow them to be positioned without regard for where other controls are (to some extent).

For instance in a project I am working on right now, I have a window that is going to be a shipping manager. I want three list views (Shipments, Packages, Items) I have a grid control with two columns; one with the Packages list and a grid splitter, the other with a nested grid with the other two lists and a grid splitter.

i have seen many designers break their window down into areas like this, and doing it with anything other than a grid just doesn't work since there are no discreet "cells" that items indirectly live in. Quite a few program windows take this design and so I guess when they had a meeting and asked what should be the default container panel, grid was the choice based on that fact.

Cory

OffApps Cory
+3  A: 

Two words: Star sizing. 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.

Robert Rossney
Agreed, but you only need it sometimes, not always. And you generally can use a DockPanel to the same effect.
Eduardo Molteni
To a somewhat similar effect, maybe. But if you want to divide a window in half, say, you can't really do that with a DockPanel. Not without doing things you probably shouldn't, like binding to the parent's ActualSize property.
Robert Rossney