WPF DataGrid 双击行 获得绑定数据

原文: WPF DataGrid 双击行 获得绑定数据

1)增加事件

2)增加对象获取

1)事件代码

Datagrid 增加事件 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
今日推荐