locked
Cannot get coordinates of tapped area

    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;
                grid.Children.Add(elli);
            }

    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.

    PLEASE HELP HELP

                
    Wednesday, July 30, 2014 1:35 PM

Answers

  • 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:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/336e4a63-0e8f-4312-8a33-8148583e78f7/grid-and-canvas?forum=wpf

    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.

    Thursday, July 31, 2014 2:44 AM

All replies