wpf
wpf copied to clipboard
Add RowSpacing and ColumnSpacing to Grid (similar to Uwp)
The Grid in UWP has a property called ColumnSpacing and a similar RowSpacing property that:
Gets or sets the uniform distance (in pixels) between grid columns.
It would be extremely useful to have this in the wpf version of Grid as well. Adding such a feature would require a minimal change to both the measure and arrange phase of the panel.
The added benefit would be huge, because on a daily basis I have to cludge around with margins on child items to make sure spacing remains correct. Having a uniform spacing would allow me to focus only on those elements in my panels that require custom spacing. It would also make it much more easy to space items dynamically if they were bindable dependency properties.
Similar request for StackPanel: https://github.com/dotnet/wpf/issues/3591
Wouldn't it be even more useful to have a property on ColumnDefinition/RowDefinition such as Margin that would let you set the space on per-column/row basis?
I think there are two arguments against having spacing on ColumnDefinition and RowDefinition:
- Standardization is key and it's different from the Uwp / WinUI implementation
- Rows (and columns) need to share spacing with their neighbours. Normal margin behavior in Wpf adds the margins together which is not what you'd expect and want from this feature. Collapsing the space to the largest space such as in
FlowDocumentswould be possible, but that's different from how margins and padding work in Wpf.
I was indeed thinking about standard margin behaviour where margins are added, you could have a margin on one side and not on the other, or possibly override the global grid spacing. It was just an idea for thought.
UWP / WinUI has many things different and sadly many things missing. I don't think we should be aiming at compatibility when there isn't one to begin with, especially in this direction from a simplified framework. I agree it's nice to have things the same, but I wouldn't hesitate to have yet another more advanced feature that the former framework is missing.
That said, I am totally fine with ColumnSpacing and RowSpacing, the expectation is clear and the RTL behaviour is obvious.
This would be an amazing feature. The way I have been working around this for years in WPF has been to insert dummy rows/columns with fixed width/height between the populated columns. It makes the XAML code very hard to maintain because every content cell is then two cells from the next instead of one.
Just do the laziest possible thing, Microsoft. In RowDefinitions and ColumnDefinitions and a fake element called GapDefinition. It would just work as adding a Row/Column Definition with a size and no index for it.
That would turn Row,Gap,Row and in the Grid you would use Row=0 and Row=1. So the index would ignore the Gap but visually, it would be inserted as if it was Row,Row,Row and using Row=0 and Row=2. I don't think it's that complicated to do and would take less than 5 years.
In Windows-only (real) Apps, I don't think anything is dethroning WPF anytime soon, no matter how hard you try.
PS: Added to Future 4 years ago. A literal nothing for any maintainer and absolutely non-breaking change. Just make a Never tag already and put some honesty into it.
@CodeAngry I do not think this pass the discussion.