前提:ContactInfo对象有ID属性且有值
//DataGrid选中改变
private void dgContact_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show(((ContactInfo)((DataGrid)sender).SelectedItem).ID.ToString());
}