[英]Windows Phone 7: How can I do something when the user clicks on an image?
I use windows phone 7, with silverlight. 我使用带有Silverlight的Windows Phone 7。 I have an image on my page and I want that when the user clicks on the image an event will raise. 我的页面上有一个图像,我希望当用户单击图像时会引发一个事件。 Moreover, If it is possible I would like to know on which point of the image the user clicked. 此外,如果可能,我想知道用户单击了图像的哪一点。
Try this you probebly have to consider the image location relative to coordinates.. the coordinates are probebly relative to the root element. 尝试此操作,您必须考虑图像相对于坐标的位置。.坐标相对于根元素要探测。
<Image MouseLeftButtonUp="image_MouseLeftButtonUp" x:Name="image" />
private void image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
string x = e.GetPosition((UIElement)sender).X.ToString();
string y = e.GetPosition((UIElement)sender).y.ToString();
}
The WP7 Silverlight Toolkit (http://silverlight.codeplex.com/) has GestureListeners where you can attach a Tap Gesture to your image and catch the event. WP7 Silverlight工具包(http://silverlight.codeplex.com/)具有GestureListener,您可以在其中将Tap Gesture附加到图像上并捕获事件。
<Image>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
Tap="OnTap"/>
</toolkit:GestureService.GestureListener>
</Image>
我检查了所有可以绑定到图像标签的事件,应该有一个名为MouseLeftButtonDown
和MouseLeftButtonUp
看看是否能使您进入正确的轨道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.