简体   繁体   English

Windows Phone 7:当用户单击图像时,我该怎么做?

[英]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>

我检查了所有可以绑定到图像标签的事件,应该有一个名为MouseLeftButtonDownMouseLeftButtonUp看看是否能使您进入正确的轨道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户单击缩略图ASP.NET时如何显示完整图像 - How can I display the full image a when user clicks the thumbnail image ASP.NET 当用户双击Windows窗体列表框时,如何触发动画启动? - How do I trigger an animation to start when the user double-clicks on a Windows Forms ListBox? 如何在Windows Phone上压缩图像 - How do I compress an image on Windows Phone C#:当用户单击按钮时如何查看图像? - C#: How do I view an image when a user clicks on a button? 用户单击批准后如何显示确认消息? - how can i put a confirmation message when the user clicks approved? 如何检测用户何时单击WebView控件中的超链接? - How can I detect when the user clicks on a hyperlink in a WebView control? 用户尝试购买商品时,Windows Phone 8应用程序引发异常 - Windows Phone 8 app throws exception when user tries to buy something 当用户按下开始按钮时,如何存储Windows Phone的数据? - How can I store the data of a windows phone when the user press Start button? 如何更改小图块的图像-Windows Phone 8? - How do I change image for small tile - Windows Phone 8? 如何更改Windows手机应用程序的背景图像 - How do I change the background image of a Windows phone app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM