Skip to content
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

When window closed with DataGrid cell is in edit mode, active edits are not committed #9874

Open
BenCamps opened this issue Oct 1, 2024 · 0 comments

Comments

@BenCamps
Copy link

BenCamps commented Oct 1, 2024

Description

The in WPF general default behavior for an editable control that supports text input is to push binding update to source when the control loses focus.
When the user closes the active window and focused elements automatically loose focus and this causes any edits on the focused control to be pushed before the window closes.
However with the DataGrid control, if the window is closed and there is a text cell in edit mode it doesn't cause the binding to push the cell contents.

This issue seems to be due to the cell control retaining keyboard focus after it has lost logical focus. Which would make since if the cell was composed of multiple separate controls which could lose and gain focus while the cell was still being edited.
See DataGridCell.OnAnyLostFocus
However when logical focus leaves the visual hierarchy of the current cell, then the current cell selection should be cleared.

Reproduction Steps

  1. Create a window with a DataGrid element
  2. Bind the DataGrid to a collection of items

While running program

  1. Begin editing DataGrid
  2. Change cell value
  3. Close window

Attached simple application for reproducing issue: WpfDataGridAppClosingIssue.zip
cell

Expected behavior

When app closes current edits are committed

Actual behavior

cell edits are not committed when window closes

Regression?

No response

Known Workarounds

Set Binding.UpdateSourceTrigger to UpdateSourceTrigger.LostFocus for each editable data grid column.
This workaround method does have some side effects: that I'm aware of, cells always push binding when cell lose focus rather than when row exited.

Impact

No response

Configuration

No response

Other information

No response

@BenCamps BenCamps changed the title When DataGrid cell is in edit mode when window closed, edits are not commted When window closed with DataGrid cell is in edit mode, active edits are not committed Oct 4, 2024
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

No branches or pull requests

1 participant