tags:

views:

537

answers:

2

Is it easily possible to specify a margin and/or padding for rows or columns in a WPF Grid?

I could of course add extra columns to space things out, but this seems like a job for padding/margins (it will give much simplier XAML). Has someone derived from the standard Grid to add this functionality?

+4  A: 

RowDefinition and ColumnDefinition are ContentElements, and Margin is strictly a FrameworkElement property. So to your question, "is it easily possible" the answer is a most definite no. And no, I have not seen any layout panels that demonstrate this kind of functionality.

You can add extra rows or columns as you suggested. But you can also set margins on a Grid element itself, or anything that would go inside a Grid, so honestly I don't see the need for this behavior in a panel.

Charlie
Agreed, though I for one would love one that allows for a cell padding property similar to ancient HTML tables :-).
Jeff Wilcox
+1  A: 

You could write your own GridWithMargin class, inherited from Grid, and override the ArrangeOverride method to apply the margins

Thomas Levesque