Search code examples
c#xamlmouse-position

PointToScreen is unknown


I want to locate two controls on the screen to dynamically create a "Line" between them (the Line is already in the XAML code and changing its Stroke will make it appear). I tried to catch the Tapped event of these controls and use the event's GetPosition(), but the line is not at the right place (the angle is correct but the line is too far). Some posts suggested to use PointToScreen. But my Visual Studio do not know System.Windows.Forms. Why ?


Solution

  • Something like that ?

     public void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                var myControl = (YourControlType)sender;                         
                var position = e.GetPosition(myControl);
                var controlPosition= myControl.PointToScreen(position);
            }