Skip to content

Fix template column edit commit and context menu regression in DataGrid_LostFocus#235

Open
kdurane wants to merge 2 commits into
AvaloniaUI:masterfrom
kdurane:master
Open

Fix template column edit commit and context menu regression in DataGrid_LostFocus#235
kdurane wants to merge 2 commits into
AvaloniaUI:masterfrom
kdurane:master

Conversation

@kdurane
Copy link
Copy Markdown

@kdurane kdurane commented Apr 23, 2026

EditingColumnIndex property was disconnected from _editingColumnIndex, causing DataGrid_LostFocus and WaitForLostFocus to always see the wrong editing column

@kdurane
Copy link
Copy Markdown
Author

kdurane commented Apr 23, 2026

fixes issue #21210 (in Avalonia main)

@kdurane
Copy link
Copy Markdown
Author

kdurane commented Apr 23, 2026

addressess #209

@kdurane kdurane changed the title Fix EditingColumnIndex property not reading _editingColumnIndex backi… Fix template column edit commit and context menu regression in DataGrid_LostFocus Apr 23, 2026
@kdurane
Copy link
Copy Markdown
Author

kdurane commented Apr 23, 2026

Fix 1: EditingColumnIndex property not reading _editingColumnIndex backing field
EditingColumnIndex was declared as an auto-property, creating a compiler-generated backing field that nothing in the DataGrid was writing to. The internal field _editingColumnIndex was used throughout the rest of the DataGrid codebase, but DataGrid_LostFocus and WaitForLostFocus both reference the property rather than the field directly, meaning they always read the default value of 0 rather than the actual editing column index. This caused editingColumn to always resolve to column 0 regardless of which column was actually being edited, sending DataGrid_LostFocus down the wrong commit path for template columns.
Fix 2: Restore popup-aware focus tracking in DataGrid_LostFocus
I only discovered this second issue after noticing a reported regression (#234) pointing to commit 7fd1e70, which simplified the visual tree walk in DataGrid_LostFocus, replacing the popup-boundary-aware dataGridWillReceiveRoutedEvent logic with a simple IsVisualAncestorOf check. This removed the handling that correctly identified when focus had moved to a popup belonging to the editing element (such as a CalendarDatePicker dropdown or a TextBox context menu) rather than genuinely leaving the DataGrid. The result was that the DataGrid would incorrectly call CommitEdit and exit edit mode whenever a popup opened, dismissing context menus and preventing date selection from committing. The fix restores the popup detection using GetVisualRoot() to compare visual roots, which is the idiomatic v12 equivalent of the original approach.
Without fix 1, fix 2 has no effect — editingColumn is always null regardless of the focus logic, so the correct branch is never reached.

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.

1 participant