我有一个数据网格,当我在这个数据网格上加载数据时,我想关注选定的行。但是我没有通过索引获得排名。如何在wpf数据网格中按索引获取行
if (gridAppointment.SelectedIndex >= 0)
{
gridAppointment.ScrollIntoView(gridAppointment.Items[gridAppointment.SelectedIndex]);
DataGridRow row = (DataGridRow)gridAppointment.ItemContainerGenerator.ContainerFromIndex(
gridAppointment.SelectedIndex);
if (row != null)
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
那么使用SelectedItem呢? –