wpfdatagrid - WPF DataGrid loses focus after row delete / cut -
i have datagrid
implemented in mvvm/prism application. datagrid
supports cut/copy/paste/delete through context menu , keyboard gestures.
i find when row deleted/cut entire datagrid
loses focus , keyboard focus moves last focused control.
is there anyway prevent this?
after removing row may want re-paste datagrid
. furthermore if grid empty there no way @ keyboard focus. clicking empty grid not give focus.
here similar question, doesn't solve issue me: datagrid looses focus when delete key pressed
you set datagrids focus in previewkeydown-event
private void thedatagrid_previewkeydown(object sender, keyeventargs e) { if (e.key == key.delete) { var grid = (datagrid)sender; focusmanager.setfocusedelement(window.getwindow(grid), grid); //not tested } }
if dont want put code in code-behind use attachedproperties in combination dependencypropertychanged-event.
how set set focus.
Comments
Post a Comment