WPF DataGrid 双击行 获得绑定数据
作者:互联网
原文:WPF DataGrid 双击行 获得绑定数据
1)增加事件
2)增加对象获取
1)事件代码
Datagrid 增加事件 MouseDoubleClick="dataGrid_MouseDoubleClick"
-
- private void dataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- DataGrid datagrid = sender as DataGrid;
- Point aP = e.GetPosition(datagrid);
- IInputElement obj = datagrid.InputHitTest(aP);
- DependencyObject target = obj as DependencyObject;
-
-
- while (target != null)
- {
- if (target is DataGridRow)
- {
- var s = this.dataGrid.SelectedItem;
- }
- target = VisualTreeHelper.GetParent(target);
- }
- }
2)获得属性
直接转换对象
对象类 s = (对象类) this.dataGrid.SelectedItem; 就可以了
var s = this.dataGrid.SelectedItem;
标签:dataGrid,MouseDoubleClick,target,datagrid,SelectedItem,DataGrid,WPF,双击 来源: https://www.cnblogs.com/lonelyxmas/p/12075407.html