I got it myseslf
private double GetColumnXPosition(DataGridColumn column, DataGrid grid)
{
double result = 0.0;
if (grid == null)
return result;
for (int i = 0; i < grid.Columns.Count; i++)
{
DataGridColumn dgc = grid.Columns[i];
if (dgc.Equals(column))
break;
result += dgc.ActualWidth;
}
return result;
}
private DataGrid GetRowsDataGrid(DataGridRow row)
{
DependencyObject result = VisualTreeHelper.GetParent(row);
while (result != null && !(result is DataGrid))
{
result = VisualTreeHelper.GetParent(result);
}
return result as DataGrid;
}
private void DgvMain_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
Point newPosition = new Point();
double rowX=0;
DataGrid dg = GetRowsDataGrid(e.Row);
if (dg != null)
{
rowX = GetColumnXPosition(e.Column, dg);
newPosition = e.Row.TranslatePoint(new Point( DgvMain.RowHeaderWidth, e.Row.ActualHeight), this);
}
if (newPosition != new Point())
{
Popup1.PlacementRectangle = new Rect(rowX + DgvMain.RowHeaderActualWidth, newPosition.Y - DgvMain.Margin.Top, 0, 0);
}
Popup1.IsOpen = true;
}
private void DgvMain_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
Popup1.IsOpen = false;
}