WPF DataGrid 双击行 获得绑定数据

时间:2019-12-20 23:54:42   收藏:0   阅读:257
原文: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;

 

原文:https://www.cnblogs.com/lonelyxmas/p/12075407.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!