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;