private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e) { if (!(e.OriginalSource is DataGrid)) { return; } switch (e.Key) { case Key.Back: BackKeyCommand?.Execute(null); this.FirstRowOrDataGridFocus(); break; default: break; } }
private void Row_PreviewKeyDown(object sender, KeyEventArgs e) { if (!(sender is DataGridRow row)) { return; } switch (e.Key) { case Key.Enter: EnterKeyCommand?.Execute(row.Item); break; case Key.Back: BackKeyCommand?.Execute(null); break; default: return; } this.FirstRowOrDataGridFocus(); e.Handled = true; }