2017-09-25 90 views
0

如何從Top的可視DataGridRow相對於本身的Top獲得垂直偏移量?從DataGridRow的頂部相對於DataGrid的頂部獲取垂直偏移量

要說清楚的是,我並不是在尋找ScrollViewer中該行的垂直偏移量。

我想檢索附加行爲的行加載中的信息,但不知道如何。

private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e) 
{ 
    DataGrid dg = this.AssociatedObject; 
    DataGridRow dgr = e.Row; 
} 
+1

https://stackoverflow.com/questions/1923697/how-can-i-get-the-position-of-a-child-元件相對到一個父 – Mishka

回答

1

你可以使用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; 
    //... 
}