Honor template content reuse during row recycling#311
Open
wieslawsoltes wants to merge 2 commits into
Open
Conversation
Owner
Author
|
Self-review completed. I found and fixed an edge case where content created from NewRowCellTemplate could be reused after the placeholder became a regular data row. Commit 86349f7 uses the row recycling placeholder state to force the correct display template and adds regression coverage. Focused tests passed 4/4, the full unit suite passed 2,252/2,252, all six CI checks are successful, and git diff --check is clean. |
wieslawsoltes
marked this pull request as ready for review
July 15, 2026 00:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Honor
DataGridTemplateColumn.ReuseCellContentwhen a recycled row is assigned to another ordinary data item, while retaining forced regeneration for template changes and edit-mode transitions.Fixes #290.
Root cause
DataGridRow.OnPropertyChangedrefreshed template cells after a recycled row received a newDataContextby callingRefreshCellContentwithnameof(DataGridTemplateColumn.CellTemplate).That refresh reason is also used for a real template-property change.
DataGridTemplateColumntherefore set_forceGenerateCellFromTemplate, discarded the existing control, and rebuilt the template. In practice, every real-to-real row recycle bypassedReuseCellContent, so the optimization worked in directGenerateElementtests but not through the actual row lifecycle.Changes
CellTemplateorNewRowCellTemplatecannot retain visuals from the old template.User and performance impact
Applications opting into
ReuseCellContentnow receive the intended behavior during virtualization: ordinary row recycling retains the existing control and lets inheritedDataContextupdate it. This avoids repeated template construction in scroll/update paths without changing the default behavior when reuse is disabled.Validation
Avalonia.Controls.DataGrid.UnitTestsproject: 2,251 passed, 0 failed.git diff --check: clean.