AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.18k stars 2.18k forks source link

Grid: Add RowSpacing and ColumnSpacing #5152

Open maxkatz6 opened 3 years ago

maxkatz6 commented 3 years ago

Same properties exist in XF and UWP https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.grid.rowspacing?view=winrt-19041 https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.grid.rowspacing?view=xamarin-forms

Probably we will need to update related controls such as GridSplitter.

Nickelony commented 3 years ago

Is this going to be added? This issue doesn't have any labels. :/

maxkatz6 commented 3 years ago

@Nickelony current Grid was ported from WPF, which doesn't have these props. And Grid's source code is not quite simple to just add it without breaking anything. So it requires some confidence and more free time to do it. Maybe WinUI open sourcing will help as well. On other hand it's possible to add some margins manually, so it's not highest priority request.

Nickelony commented 3 years ago

The way I handled a simulated RowSpacing in my project is by adding extra rows with uniform size:

RowDefinitions="*, 3, *, 3, *, 3, *"

Maybe this could be silently implemented in code behind and make the extra spacing rows simply not have an index? Idk I'm just giving ideas. :P

Nickelony commented 3 years ago

Just managed to make a custom control which inherits from Grid:

image

Repo link to the control: https://github.com/Nickelony/AvaloniaSpacedGrid

maxkatz6 commented 3 years ago

@Nickelony this implementation makes sense as separated control, but can't be used in the framework as part of Grid, because developers expect Row/ColumnDefinitions to be exactly the same as they were defined, without spacing additions added by the control. Ideally row and column spacing calculation should be part of Measure/Arrange methods in Grid implementation. Thank you for creating this control though! It will help somebody, who will need this solution.

Btw, it's better to recalculate definitions in OnPropertyChanged method override, because property setter won't be called, if developer will use grid.SetValue(RowSpacingProperty, value) directly, as well as it won't work with styles. https://github.com/Nickelony/SpacedGrid.Avalonia/blob/main/SpacedGrid.Avalonia/SpacedGrid.cs#L22

Nickelony commented 3 years ago

@Nickelony this implementation makes sense as separated control, but can't be used in the framework as part of Grid, because developers expect Row/ColumnDefinitions to be exactly the same as they were defined, without spacing additions added by the control.

I didn't expect this solution to be accepted into the framework, because I know it's kind of a hacky solution really.

Btw, it's better to recalculate definitions in OnPropertyChanged method override, because property setter won't be called, if developer will use grid.SetValue(RowSpacingProperty, value) directly, as well as it won't work with styles. https://github.com/Nickelony/SpacedGrid.Avalonia/blob/main/SpacedGrid.Avalonia/SpacedGrid.cs#L22

Fixed. Thanks for the tip! :)