Cannot get coordinates of tapped area RRS feed

  • Question

  •         private void grid_PointerPressed(object sender, PointerRoutedEventArgs e)

                Ellipse elli = new Ellipse();
                PointerPoint pt = e.GetCurrentPoint(null);
                elli.Margin = new Thickness(pt.Position.X, pt.Position.Y, 0, 0);
                elli.Stroke = new SolidColorBrush(Windows.UI.Colors.White);
                elli.StrokeThickness = 5;
                elli.Height = 10;
                elli.Width = 10;

    Above snippet is PointerPressed event of grid.

    I want to get the coordinate of mouse click and draw an ellipse there.

    However, this code is not giving me desired result because ellipse is not getting drawn on that coordinate..

    If i click somewhere on grid, ellipse appears on some other place.


    Wednesday, July 30, 2014 1:35 PM


  • Hi,

    I think this ia because the difference between Grid and Canvas.A Canvas is absolute - the content (children) won't size to fit and always appear where you specify them, relative to the Canvas upper left corner.

    Whereas the grid can size to fit the children, a canvas does not.

    You can refer to the discussion:


    Best Wishes!

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    • Marked as answer by Anne Jing Thursday, August 7, 2014 1:16 AM
    Thursday, July 31, 2014 2:44 AM

All replies