Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Why all the love for the Grid control?

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?

like image 945
Eduardo Molteni Avatar asked Mar 15 '10 15:03

Eduardo Molteni


4 Answers

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.

like image 131
Robert Rossney Avatar answered Nov 04 '22 17:11

Robert Rossney


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.

like image 2
Reed Copsey Avatar answered Nov 04 '22 18:11

Reed Copsey


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.

like image 1
TomTom Avatar answered Nov 04 '22 19:11

TomTom


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

like image 1
CodeWarrior Avatar answered Nov 04 '22 19:11

CodeWarrior