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. 將焦點移至下一個單元格上按Enter鍵WPF DataGrid中按?
- 2. 按下回車鍵後,JSpinner不會轉移焦點
- 3. 將焦點移到下一個控件上用Silverlight按下的回車鍵
- 4. 將焦點移至DataGrid中新行的第一列(WPF)
- 5. 按下回車鍵時,Java將焦點放在jbutton上
- 6. WPF DataGrid - 如何將鍵盤焦點移動到新添加的行之後按Tab鍵
- 7. 在按下WPF DataGrid中的Enter鍵時移至下一列
- 8. 禁用WPF DataGrid行中的焦點
- 9. 當按下回車鍵時更改焦點控制
- 10. 將焦點設置爲DataGrid代碼中的第一個單元格WPF MVVM
- 11. 按下回車鍵
- 12. WPF MVVM DataGrid行到另一個DataGrid
- 13. WPF和MVVM:如何將焦點自動移動到下一個控件
- 14. 在EditText中輸入數據,然後按下回車鍵回車
- 15. Excel的用戶窗體 - 焦點返回到組合框按下回車鍵
- 16. Wpf DataGrid的焦點問題
- 17. 按下一個按鈕與回車鍵
- 18. ncurses中按回車鍵後光標不會移動到新行
- 19. 彈出控制器後按下回車鍵按鈕
- 20. WPF MVVM加載焦點域
- 21. 按下任意鍵而不按下回車鍵退出「do while」?
- 22. 如何將焦點集中在下一個輸入字段上,並按下回車鍵in angular4
- 23. 點擊「回車」按鍵
- 24. 按Enter鍵將焦點移到下一步在C#中的網頁控制
- 25. WPF的DataGrid失去焦點的行刪除之後/切割
- 26. 從WPF DataGrid中的特定列中移除焦點
- 27. jquery焦點/焦點按鍵
- 28. WPF DataGrid行樣式與MVVM
- 29. WPF,MVVM datagrid行綁定
- 30. 焦點不會移動回車鍵在asp.net
看到我最後的編輯,請感謝 – 2012-05-08 05:11:49
如果要創建用戶控制用戶控制沒有問題,從數據網格導出您仍然可以選擇在XAML代碼,你會得到屬性的探險家在財產資源管理器,你可以找到左側的網站上的數據網格事件和之後,雙擊...它會在代碼後面創建一個事件 – 2012-05-08 12:29:14
我不使用代碼隱藏,因爲它是mvvm。 – 2012-05-08 14:43:40