var button = new Button(); button.Text = "Click me"; // Add button to parent layout parentLayout.Children.Add(button); // Get global coordinates of button Point globalPoint = button.ChangeCoordinatesTo(parentLayout, new Point(0, 0));
var button = new Button(); button.Text = "Click me"; // Add button to parent layout parentLayout.Children.Add(button); // Get global coordinates of button Point globalPoint = button.ChangeCoordinatesTo(parentLayout, new Point(0, 0)); // Convert global point to local point Point localPoint = parentLayout.ChangeCoordinatesTo(button, globalPoint);In this example, we create a new button and add it to a parent layout. We then call the ChangeCoordinatesTo method on the button, passing in the parent layout as the target coordinate system and a point (0,0) as the origin point. This gives us the global coordinates of the button relative to the parent layout. We then call the ChangeCoordinatesTo method again, but this time we pass in the button as the target coordinate system and the globalPoint we obtained earlier. This gives us the local coordinates of the button relative to its own coordinate system. The package library used is Xamarin.Forms.