WPF Mouse Position and Visible dot not the same place

I'm trying to make a simple desktop application in WPF and I'm having problems placing a dot the same place my mouse is. First picture is when i click almost top left. Second picture is almost clicking bottom right. Third picture is my Xaml file.

Here is the relevant C# code
private void MainGrid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            // Get the mouse click position relative to the mainGrid
            Point clickPosition = e.GetPosition(mainGrid);

            // Show a dot at the click position
            ShowDot(dotEnd, clickPosition);
        }
private void ShowDot(Ellipse dot, Point position)
{
    dot.Margin = new Thickness(position.X - dot.Width / 2, position.Y - dot.Height / 2, 0, 0);

    // Show the dot
    dot.Visibility = Visibility.Visible;
}
image_2024-01-18_161253436.png
image.png
image.png
Was this page helpful?