WPF:如何将重点放在数据网格的特定行上? [英] WPF: How do I set the focus on a datagrid to a specific row?
本文介绍了WPF:如何将重点放在数据网格的特定行上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将焦点放在数据网格的第一行。
I would like to set the focus on the first row of a data grid.
到目前为止,这是我所拥有的:
This is what I have so far:
Keyboard.Focus(ResultsGrid)
If result.Count > 0 Then
ResultsGrid.SelectedIndex = 0
End If
这将设置关注数据网格,而不关注行本身。
This will set the focus to the datagrid, but not the row itself.
推荐答案
选择行之后,您将必须通过以下方式将焦点设置在行上:
After selecting the row you will have to set the focus on the row in the following way:
ResultsGrid.SelectedIndex = index;
DataGridRow row = (DataGridRow)ResultsGrid.ItemContainerGenerator.ContainerFromIndex(index);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
这篇关于WPF:如何将重点放在数据网格的特定行上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文