Search code examples
wpfuser-interfacegridstackpanel

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?


Solution

  • 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.