Hi waterharbin,
根据你的描述,我写了下面的代码来选择DataGrid的行,你可以参考。
<sdk:DataGrid x:Name="TESTDG" HorizontalAlignment="Left" Height="145" Margin="30,320,0,0" VerticalAlignment="Top" Width="320"/>
<Button x:Name="button1" Content="Set row" HorizontalAlignment="Left" Margin="370,390,0,0" VerticalAlignment="Top" Width="75" Click="button1_Click"/>
private void button1_Click(object sender, RoutedEventArgs e)
{
SetDataGridSelectedRow(TESTDG , listauthors[2]); ;
}
private void SetDataGridSelectedRow(DataGrid dataGrid, Author model)
{
int index = -1;
foreach (var p in dataGrid.ItemsSource)
{
Author point = p as Author;
if (point == null) continue;
if (point.ID == model.ID)
{
List<Author> list = dataGrid.ItemsSource as List<Author>;
index = list.IndexOf(point);
break; ;
}
}
if (index != -1)
dataGrid.SelectedIndex = index;
}

Best Regards,
Yohann Lu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.