Double-click the wpf DataGrid Control to obtain the current row.
<DataGrid Margin = "10" HorizontalAlignment = "Left" verticalignment = "Top" AutoGenerateColumns = "False" ItemsSource = "{Binding}" Name = "dg_cards" MouseDoubleClick = "success"> <DataGrid. columns> <maid Header = "ID" Width = "40" Binding = "{Binding index}" IsReadOnly = "True"/> <maid Header = "enable" Width = "50 "> <maid. cellTemplate> <DataTemplate> <CheckBox Name = "cbStatus" MinWidth = "{Binding ID}" Uid = "{Binding Path = ID}" IsChecked = "{Binding IsChecked}" Tag = "{Binding ID}"/> </DataTemplate> </DataGridTemplateColumn. cellTemplate> </maid> <maid Header = "bayonet" Width = "80" IsReadOnly = "True" Binding = "{Binding cardname}"/> <maid Header = "eight ports card "Width =" 80 "> <DataGridTemplateColumn. cellTemplate> <DataTemplate> <CheckBox Name = "cbeight" IsChecked = "{Binding IsEChecked}"/> </DataTemplate> </DataGridTemplateColumn. cellTemplate> </DataGridTemplateColumn> <DataGridTextColumn Header = "operation" Width = "80" IsReadOnly = "True" Binding = "{Binding op}"/> </DataGrid. columns> </DataGrid>
Background code:
Private void dg_cards_MouseDoubleClick (object sender, MouseButtonEventArgs e) {bool isEight = false; DataGrid dg = sender as DataGrid; // double-click to obtain the control of the third column DataGridTemplateColumn templeColumn1 = dg. columns [3] as maid; FrameworkElement fwElement1 = dg_cards.Columns [3]. getCellContent (dg. currentItem); CheckBox cBox1 = templeColumn1.CellTemplate. findName ("cbeight", fwElement1) as CheckBox; if (bool) cBox1.IsChecked) {isEight = true ;}}