0
A
回答
2
private void dataGrid1_KeyUp(object sender, KeyEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
//here we find the Row is selected
//then we check is the row last row
while ((dep != null) && !(dep is DataGridRow) && !(dep is DataGridColumnHeader))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null)
return;
if (dep is DataGridRow)
{
DataGridRow row= dep as DataGridRow;
//untill here we find the selected row and here we check if it
//the last row our focus go to next control after datagrid
if (row.GetIndex() == dataGrid1.Items.Count - 1)
{
dataGrid1.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
dataGrid1.UnselectAll();
}
}
}
設定此事件的關鍵你的DataGrid的。使用System.Windows.Controls.Primitives也使用這個參考。把datagrid和其他一些控件放到你的窗口中。當你到達最後一行時,它將改變集中到下一個控制。我會出現在你富有最後一排,因爲這如果(row.GetIndex()== dataGrid1.Items.Count - 1)
我使用數據網格與fullrowselect作爲選擇模式。如果你想使用數據網格細胞選擇模式請給我留言。
+0
當我到達第一排時,它甚至移動到下一個控件。但我想在這裏是當我到達最後一行和第二列在null然後我想要移動到下一個控制。 – 2012-05-07 20:53:04
+0
我沒有CodeBehind文件..我創建一個從DataGrid派生的CustomDataGrid。 – 2012-05-08 10:21:23
相關問題
- 1. 按下回車鍵後,JSpinner不會轉移焦點
- 2. 將焦點移到下一個控件上用Silverlight按下的回車鍵
- 3. 將焦點移至DataGrid中新行的第一列(WPF)
- 4. 按下回車鍵時,Java將焦點放在jbutton上
- 5. WPF DataGrid - 如何將鍵盤焦點移動到新添加的行之後按Tab鍵
- 6. 在按下WPF DataGrid中的Enter鍵時移至下一列
- 7. 禁用WPF DataGrid行中的焦點
- 8. 將焦點設置爲DataGrid代碼中的第一個單元格WPF MVVM
- 9. WPF MVVM DataGrid行到另一個DataGrid
- 10. 在EditText中輸入數據,然後按下回車鍵回車
- 11. ncurses中按回車鍵後光標不會移動到新行
- 12. 如何將焦點集中在下一個輸入字段上,並按下回車鍵in angular4
- 13. WPF MVVM加載焦點域
- 14. 點擊「回車」按鍵
- 15. WPF的DataGrid失去焦點的行刪除之後/切割
- 16. 焦點不會移動回車鍵在asp.net
- 17. 按回車鍵退出(Java)
- 18. 從WPF DataGrid中的特定列中移除焦點
- 19. 將焦點從一個控件移動到另一個控件,只需按回車鍵Jquery
- 20. 按回車鍵
- 21. wpf mvvm datagrid selectedrow
- 22. WPF:按下回車鍵時觸發事件的文本框
- 23. 如何在WPF RichTextBox的最後一行設置焦點
- 24. 在flex中編輯之後,將焦點返回到datagrid列
- 25. 在Silverlight Datagrid中,如何在焦點離開最後一行時添加新行?
- 26. 按下按鈕進行打印後,將焦點放在另一個按鈕上
- 27. WPF,XAML Datagrid - 僅在最後一行啓用上下文菜單
- 28. 在GNOME的wxPython中按下快捷鍵後抓取焦點
- 29. 確定QWidget的是有按鈕按下前的最後焦點
- 30. 使用箭頭鍵將焦點移動到下一個控件
看到我最後的編輯,請感謝 – 2012-05-08 05:11:49
如果要創建用戶控制用戶控制沒有問題,從數據網格導出您仍然可以選擇在XAML代碼,你會得到屬性的探險家在財產資源管理器,你可以找到左側的網站上的數據網格事件和之後,雙擊...它會在代碼後面創建一個事件 – 2012-05-08 12:29:14
我不使用代碼隱藏,因爲它是mvvm。 – 2012-05-08 14:43:40