Wpf 获取相对于DataGrid顶部的DataGridRow顶部的垂直偏移
如何从可见的Wpf 获取相对于DataGrid顶部的DataGridRow顶部的垂直偏移,wpf,datagrid,Wpf,Datagrid,如何从可见的DataGridRow的Top获取相对于DataGrid本身的Top的垂直偏移 明确地说,我不是在ScrollViewer中查找行的垂直偏移量 我希望在加载附加行为中的行时检索此信息,但不确定如何检索 private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { DataGrid dg = this.AssociatedObject; DataGridRow dgr = e.Row;
DataGridRow
的Top
获取相对于DataGrid
本身的Top
的垂直偏移
明确地说,我不是在ScrollViewer
中查找行的垂直偏移量
我希望在加载附加行为中的行时检索此信息,但不确定如何检索
private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGrid dg = this.AssociatedObject;
DataGridRow dgr = e.Row;
}
您可以使用
TranslatePoint
方法:
private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGrid dg = this.AssociatedObject;
DataGridRow dgr = e.Row;
Point p = dgr.TranslatePoint(new Point(0, 0), dg);
double verticalDistance = p.Y;
//...
}