How to get touch pointer inside a specific Grid

2020-05-01 09:19发布

问题:

I have a layout like the following: grid-1 grid-2 grid-3 ... one nested inside of another.

Within Grid-3, there are 10x10 matrix of images. What I'd like to know is how do I know a touch is within grid-3 and which image is touched? I read the example from eBook and code:

primaryTouchPoint.TouchDevice.DirectlyOver == txtblk

I tries to use it with my grid-3 name, the touch pointer only at the very top line of grid-3. And I don't want to write 100 line of if-else statement for each image. And also when I use grid-3.Width, actualWidth, these method all return 0. How do I know the size of this grid-3 on screen?

-Henry

回答1:

One way would be to wrap each image inside a control that has a click event, like a button. Point all the click event handlers to a single method and grab the child image from this.