2011-08-23 43 views
0

我用silverlight的windows phone 7。 我的页面上有一张图片,我希望当用户点击图片时会引发一个事件。此外,如果有可能我想知道用户点击了图像的哪个点。Windows Phone 7:当用户点击图像时,我该怎么做?

+0

注意手指比像素更大,所以你需要让大量的空间在你的位置检测考虑到这种差异或您检测触摸未必是用户正打算。 –

回答

4

试试这个,你必须考虑图像相对于坐标的位置..坐标是相对于根元素探测的。

<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(); 
    } 
0

我检查了所有可以绑定到图片标签的事件,应该有一个名为MouseLeftButtonDownMouseLeftButtonUp的活动,看看是否让您走上正轨。

+0

谢谢,我查过了。我使用了MouseLeftButtonDown,当我点击图像时,它确实进入了我的功能。但是,我没有找到一种方法来获取图像内点击的位置。 – mynameisalon

1

的WP7 Silverlight工具包(http://silverlight.codeplex.com/)具有GestureListeners在那里你可以将点击手势,以图像和捕捉事件。

<Image> 
    <toolkit:GestureService.GestureListener> 
       <toolkit:GestureListener 
        Tap="OnTap"/> 
    </toolkit:GestureService.GestureListener> 
    </Image> 
+0

它也给你在事件上的位置(e.GetPosition)。 – invalidusername