-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[Grid] Add RowSpacing and ColumnSpacing #18077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
You can test this PR using the following package version. |
|
@cla-avalonia agree |
/// Defines the <see cref="ColumnSpacing"/> property. | ||
/// </summary> | ||
public static readonly StyledProperty<double> ColumnSpacingProperty = | ||
AvaloniaProperty.Register<Grid, double>(nameof(ColumnSpacingProperty)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add coercion for negative values? Or does UWP support them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
negative spacing is not recommended feature, but it is supported in uwp/winui3. And so do this PR. This PR support negative spacing, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think we should support negative Spacing if possible. It matches with what is allowed for Margin/Padding which can be negative.
There are some rare layout cases it's useful and by default the math usually supports negatives for free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now both the spacing in uwp/winui3 and in these 3 PRs don't support negative values in principle, but in practice they do support (
Great work! This has been a nice to have for a long time. |
I'm marking this PR with |
It also matches UWP/WinUI as-is and I've never heard of concerns with that API. |
We need this 😁 |
Public API for review: namespace Avalonia.Controls
{
public class Grid : Panel
{
+ public static readonly StyledProperty<double> RowSpacingProperty;
+ public static readonly StyledProperty<double> ColumnSpacingProperty;
+ public double RowSpacing { get; set; }
+ public double ColumnSpacing { get; set; }
}
} |
The API has been approved. The implementation will be reviewed soon. |
This PR is partially based on the implementation of WinUI 3 and was written by @Poker-sang and me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
A very nice feature to have :)
Elements overflow when there's not enough space 2025-03-19.02-08-20.mp4Element shown in video<Border Background="{DynamicResource UiTheme01}" BorderBrush="{DynamicResource UiTheme04}"
BorderThickness="1" CornerRadius="8">
<Grid Margin="8" ColumnSpacing="8" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" VerticalAlignment="Center" Text="Путь до Steam:" />
<TextBox Name="SteamPathTextBox" Grid.Column="1" VerticalAlignment="Center"
Background="{DynamicResource UiTheme02}" BorderThickness="0" Text="C:\Program Files\Steam\steam.exe" />
<Button Grid.Column="2" Width="32" Height="32" VerticalAlignment="Center" Click="SetSteamPath">
<lucideAvalonia:Lucide Icon="Folder" StrokeBrush="{DynamicResource White}" />
</Button>
</Grid>
</Border> Avalonia nightly |
What does the pull request do?
Add

RowSpacing
andColumnSpacing
properties forGrid
, just like in UWP and WinUI 3.What is the updated/expected behavior with this PR?
Grid
with various children.RowSpacing
andColumnSpacing
to non-zero values.How was the solution implemented (if it's not obvious)?
Add the corresponding spacing before calculating the position of each
RowDefinition
orColumnDefinition
.Subtract spacing before calculating stars when
GridUnitType=star
.Checklist
Breaking changes
None
Obsoletions / Deprecations
None
Fixed issues
Fixes #5152