I am trying to set the position of an Image based on a tap / click like this (note "contentGrid" is the only child of Page and fills the screen)
private void contentGrid_Tapped(object sender, TappedRoutedEventArgs e)
{
Uri uri = new Uri("ms-appx:///Images/Test.png");
BitmapImage bitmap = new BitmapImage(uri);
Image image = new Image();
image.Source = bitmap;
// The .png is a 30px by 30px image
image.Width = 30;
image.Height = 30;
image.Stretch = Stretch.None;
Point tappedPoint = e.GetPosition(contentGrid);
TranslateTransform posTransform = new TranslateTransform();
posTransform.X = tappedPoint.X;
posTransform.Y = tappedPoint.Y;
image.RenderTransform = posTransform;
contentGrid.Children.Add(image);
}
The result is that the Image of Test.png appears on the page when clicked, but not at the position where I tap / click. It is offset visually by half the page width and down by half the page height.
I am trying to understand relative positions here - what's the best way to transform the Image to the point where the user actually tapped / clicked?