Skip to content

Fix null reference in DataGrid layout rounding scroll logic#243

Merged
MrJul merged 2 commits into
AvaloniaUI:masterfrom
zrt2399:fix_issue_121
Jun 23, 2026
Merged

Fix null reference in DataGrid layout rounding scroll logic#243
MrJul merged 2 commits into
AvaloniaUI:masterfrom
zrt2399:fix_issue_121

Conversation

@zrt2399

@zrt2399 zrt2399 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Fix a layout-rounding edge case in DataGrid.ComputeDisplayedColumns.
When UseLayoutRounding is enabled, column layout can differ slightly from the logical ActualWidth-based scrolling calculations due to pixel rounding. After resizing and maximizing the window, this can leave a small positive horizontal offset even though the first displayed scrolling column is already the first visible scrolling column.
In that state, GetPreviousVisibleScrollingColumn(...) correctly returns null, because there is no previous scrolling column. The existing code assumed a previous column must exist whenever _horizontalOffset > 0, which could lead to a null dereference.
This change handles that boundary condition explicitly. If no previous visible scrolling column exists, the grid clamps the horizontal offset state back to zero and marks the displayed column state as invalidated. Otherwise, it preserves the existing behavior for partially scrolling in the previous column.
This prevents a crash while keeping the scroll/display state consistent with the actual leftmost scrolling column.

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes make sense. The returned values from GetPrevious/NextVisibleScrollingColumn could definitely be null.

@MrJul MrJul merged commit 8d25396 into AvaloniaUI:master Jun 23, 2026
1 check passed
This was referenced Jun 23, 2026
fuzzzerd pushed a commit to fuzzzerd/SharpFM that referenced this pull request Jun 30, 2026
Updated [Avalonia](https://github.com/AvaloniaUI/Avalonia/) from 12.0.4
to 12.0.5.

<details>
<summary>Release notes</summary>

_Sourced from [Avalonia's
releases](https://github.com/AvaloniaUI/Avalonia//releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/AvaloniaUI/Avalonia//commits).
</details>

Updated
[Avalonia.Controls.DataGrid](https://github.com/AvaloniaUI/Avalonia.Controls.DataGrid)
from 12.0.0 to 12.0.1.

<details>
<summary>Release notes</summary>

_Sourced from [Avalonia.Controls.DataGrid's
releases](https://github.com/AvaloniaUI/Avalonia.Controls.DataGrid/releases)._

## 12.0.1

## What's Changed
* Update DataGridColumn sort binding checks by @​rabbitism in
AvaloniaUI/Avalonia.Controls.DataGrid#230
* Fix template column edit commit and context menu regression in
DataGrid_LostFocus by @​kdurane in
AvaloniaUI/Avalonia.Controls.DataGrid#235
* Fix null reference in DataGrid layout rounding scroll logic by
@​zrt2399 in
AvaloniaUI/Avalonia.Controls.DataGrid#243
* Fix ScrollBar not reacting to ScrollViewer.AllowAutoHide property
changes by @​zrt2399 in
AvaloniaUI/Avalonia.Controls.DataGrid#241
* Update Avalonia to 12.0.5 by @​MrJul in
AvaloniaUI/Avalonia.Controls.DataGrid#246

**Full Changelog**:
AvaloniaUI/Avalonia.Controls.DataGrid@12.0.0...12.0.1

Commits viewable in [compare
view](https://github.com/AvaloniaUI/Avalonia.Controls.DataGrid/commits/12.0.1).
</details>

Updated [Avalonia.Desktop](https://github.com/AvaloniaUI/Avalonia/) from
12.0.4 to 12.0.5.

<details>
<summary>Release notes</summary>

_Sourced from [Avalonia.Desktop's
releases](https://github.com/AvaloniaUI/Avalonia//releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/AvaloniaUI/Avalonia//commits).
</details>

Updated [Avalonia.Fonts.Inter](https://github.com/AvaloniaUI/Avalonia/)
from 12.0.4 to 12.0.5.

<details>
<summary>Release notes</summary>

_Sourced from [Avalonia.Fonts.Inter's
releases](https://github.com/AvaloniaUI/Avalonia//releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/AvaloniaUI/Avalonia//commits).
</details>

Updated
[Avalonia.Themes.Fluent](https://github.com/AvaloniaUI/Avalonia/) from
12.0.4 to 12.0.5.

<details>
<summary>Release notes</summary>

_Sourced from [Avalonia.Themes.Fluent's
releases](https://github.com/AvaloniaUI/Avalonia//releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/AvaloniaUI/Avalonia//commits).
</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants