I’m a tad frustrated by the default templates used by VisualStudio and Expression Blend for WPF. The XAML always starts you out with a Grid. WTF?
The Grid panel is the most inefficient of the panels. It’s also not all that easy to use for most layouts. In other words, its the layout I would expect most developers to use the second least often (Canvas takes the bottom spot).
Don’t get me wrong. There’s plenty of scenarios in which Grid is your best layout choice. However, there’s even more scenarios where it’s not. Rarely is it the panel I’ll want my Window/Page to use by default. I almost always rip that Grid out of the generated XAML and replace it with either a DockPanel or a StackPanel.
So why the harsh tone to this rant? After all, it’s not that big of a deal to replace it, if it’s not appropriate.
The tone is harsh, because having Grid as the default panel generated by tools is leading the unwashed developers into some bad habits. Most developers don’t understand why Grid isn’t as appropriate as other panels. When they see it being used by default, they think it’s the panel they should fall back on by default. This leads to an overuse of the panel. That really bothers me. How many times have you seen a Grid used when there’s a single column and/or row, for instance?
Sorry, this is partially a religious debate. The performance of a Grid isn’t so bad as to matter most of the time. But I still have the hairs on the back of my neck stand on end the majority of the time I see a Grid used in WPF. The fact that the generated XAML encourages this doesn’t help.
Update: Here’s a classic example. The recently released Prism contains a "view" called OrdersToolbar. The OrdersToolbar.xaml file contains some lovely code in which the default template’s Grid element was left in the source. It’s only child element is a horizontal StackPanel that really defines the layout for the user control. Remove the Grid and the resulting user control is functionally identical, with easier to understand XAML markup and theoretically better performance (yeah, the perf hit here is not noticeable to the user and probably very difficult to measure, so I don’t want to make too much out of that, but it is still there). Maybe the template shouldn’t include anything but the Window/Page/UserControl, but it certainly shouldn’t include a Grid, IMHO.