WPF - Translate point relative to MainWindow so that it changes coordinates relative to child control

Is it possible to translate a point relative to MainWindow relative to one of its child controls? For example, let's say that the upper left upper corner of the control was at 500, 500 with respect to MainWindow, what code converts this number to (0, 0)? I would like the solution to be an agnostic of the layout mechanism (i.e. it didn’t require me to give birth to a control on the canvas and use the Top and Bottom methods).

+4
source share
1 answer

See UIElement.TranslatePoint . For instance:

 var translatedPoint = mainWindow.TranslatePoint(new Point(500, 500), childControl) 
+7
source

Source: https://habr.com/ru/post/1306279/


All Articles