2012-08-07 42 views
0

我在WPF應用程序中有XamDataGrid(版本2011.2),當用戶已選中「添加新行」時我需要重點返回到Add New行的第一個單元格,以便他們可以輸入另一個記錄,默認行爲將焦點放在剛剛添加的記錄上。如何在添加行後將鍵盤焦點設置到添加行

我試圖使用DataPresenterCommands來移動焦點或找到一種方法來設置myGrid.Records.DataPresenter.ActiveCell但沒有任何成功。

我需要與this question中提到的功能相同的功能,但對於Infragistics的XamDataGrid。

有沒有人有任何想法?

回答

2

感謝Infragistics支持論壇上的Yanko Nikolov尋找解決方案(我在尋找答案時多少漏掉了)。

解決方法是將此代碼添加到數據網格的預覽鍵向下事件。

private void xamDataGrid1_PreviewKeyDown(object sender, KeyEventArgs e) 
{ 
    if (e.Key == Key.Enter) 
    { 
     Dispatcher.BeginInvoke(new Action(() => 
     { 
      CellValuePresenter.FromCell(xamDataGrid1.RecordManager.CurrentAddRecord.Cells[0]).Editor.StartEditMode(); 
     }), DispatcherPriority.Background, null); 
    }   
} 
相關問題