WPFのDataGridにデータをバインド取得する行をダブルクリックして

オリジナル: DataGridのバインディングWPFデータ取得する行をダブルクリックします

1)増加イベント

2)増加目標獲得

 

 

1)イベントコード

データグリッド増加イベントMouseDoubleClick =「dataGrid_MouseDoubleClick」


  
  
  1. private void dataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
  2. {
  3. DataGrid datagrid = sender as DataGrid;
  4. Point aP = e.GetPosition(datagrid);
  5. IInputElement obj = datagrid.InputHitTest(aP);
  6. DependencyObject target = obj as DependencyObject;
  7. while (target != null)
  8. {
  9. if (target is DataGridRow)
  10. {
  11. var s = this.dataGrid.SelectedItem;
  12. }
  13. target = VisualTreeHelper.GetParent(target);
  14. }
  15. }

2)プロパティを取得します

直接変換対象

オブジェクト・クラスS =(オブジェクトクラス)this.dataGrid.SelectedItem;それ

   var s = this.dataGrid.SelectedItem;
 
 

 

おすすめ

転載: www.cnblogs.com/lonelyxmas/p/12075407.html