Skip to content

Prevented setting 0 to ColumnSpan or RowSpan. #18516

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

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

abenedik
Copy link
Contributor

The current code allows setting 0 to ColumnSpan or RowSpan.

But if this is done, for example, by calling Grid.SetColumSpan(control, 0), the following exception is thrown from Avalonia's layout pass:

ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')'

in

>	Avalonia.Base.dll!Avalonia.Collections.AvaloniaList<System.__Canon>.this[int].get(int index) Line 114	C#
 	Avalonia.Controls.dll!Avalonia.Controls.Grid.GetLengthTypeForRange(System.Collections.Generic.IReadOnlyList<Avalonia.Controls.DefinitionBase> definitions = {Avalonia.Controls.ColumnDefinitions}, int start = 0, int count = 0)	Unknown
 	Avalonia.Controls.dll!Avalonia.Controls.Grid.ValidateCellsCore()	Unknown
 	Avalonia.Controls.dll!Avalonia.Controls.Grid.ValidateCells()	Unknown
 	Avalonia.Controls.dll!Avalonia.Controls.Grid.MeasureOverride(Avalonia.Size constraint = {Avalonia.Size})	Unknown
 	Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize = {Avalonia.Size}) Line 395	C#
 	Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize = {Avalonia.Size}) Line 278	C#
 	Avalonia.Base.dll!Avalonia.Layout.LayoutManager.Measure(Avalonia.Layout.Layoutable control = "Grid (Name = BottomOptionsGrid)") Line 264	C#
 	Avalonia.Base.dll!Avalonia.Layout.LayoutManager.ExecuteMeasurePass() Line 223	C#
 	Avalonia.Base.dll!Avalonia.Layout.LayoutManager.InnerLayoutPass() Line 207	C#
 	Avalonia.Base.dll!Avalonia.Layout.LayoutManager.ExecuteLayoutPass() Line 130	C#

In WPF, the ColumnSpan property immediately throws an ArgumentOfOutRange exception when 0 is set to ColumSpan.

This prevents exception that is thrown in Layoutable.MeasureCore if 0 is set to ColumnSpan (for example by calling Grid.SetColumnSpan). In WPF, the ColumnSpan property immediatelly throws ArgumentOfOutRange exception when 0 is set to ColumSpan.
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0055727-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Mar 24, 2025

  • All contributors have signed the CLA.

@abenedik
Copy link
Contributor Author

@cla-avalonia agree

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

Grid was ported from WPF, where RowSpan and ColumnSpan correctly have > 0 validation, which was probably lost at some point.

@MrJul MrJul added this pull request to the merge queue Mar 24, 2025
Merged via the queue into AvaloniaUI:master with commit c6cfcba Mar 24, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants