C# Windows Phone 7:当用户单击图像时,我如何执行操作?

C# Windows Phone 7:当用户单击图像时,我如何执行操作?,c#,silverlight,windows-phone-7,C#,Silverlight,Windows Phone 7,我使用WindowsPhone7和silverlight。 我在我的页面上有一个图像,我希望当用户点击该图像时,事件将引发。此外,如果可能的话,我想知道用户单击图像的哪个点。我已经检查了所有可以绑定到图像标记的事件,应该有一个名为MouseLeftButtonDown和MouseLeftButtonUp的按钮,看看这是否能让你走上正轨。我已经检查了所有可以绑定到图像标签的事件,应该有一个叫 MouseLeftButtonDown < /代码>和 MouseLeftButtonUp < /代码>看

我使用WindowsPhone7和silverlight。
我在我的页面上有一个图像,我希望当用户点击该图像时,事件将引发。此外,如果可能的话,我想知道用户单击图像的哪个点。

我已经检查了所有可以绑定到图像标记的事件,应该有一个名为
MouseLeftButtonDown
MouseLeftButtonUp
的按钮,看看这是否能让你走上正轨。

我已经检查了所有可以绑定到图像标签的事件,应该有一个叫<代码> MouseLeftButtonDown < /代码>和<代码> MouseLeftButtonUp < /代码>看看这是否使你走上正确的轨道。

< P>试试这个,你必须考虑相对于坐标的图像位置。坐标可能是相对于根元素的

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

私有void image_MouseLeftButtonUp(对象发送器,MouseButtonEventArgs e)
{
字符串x=e.GetPosition((UIElement)sender.x.ToString();
字符串y=e.GetPosition((UIElement)sender.y.ToString();
}

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

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

私有void image_MouseLeftButtonUp(对象发送器,MouseButtonEventArgs e)
{
字符串x=e.GetPosition((UIElement)sender.x.ToString();
字符串y=e.GetPosition((UIElement)sender.y.ToString();
}

WP7 Silverlight工具包(http://silverlight.codeplex.com/)具有手势侦听器,您可以在其中向图像附加轻触手势并捕捉事件

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


WP7 Silverlight工具包(http://silverlight.codeplex.com/)具有手势侦听器,您可以在其中向图像附加轻触手势并捕捉事件

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


谢谢,我查过了。我使用MouseLeftButtonDown,当我点击图片时,它真正进入了我的功能。但是,我没有找到一种方法来获取图像中单击的位置。谢谢,我检查过了。我使用MouseLeftButtonDown,当我点击图片时,它真正进入了我的功能。但是,我没有找到一种方法来获取图像中单击的位置。请注意,手指比像素大得多,因此您需要在位置检测中留出大量空间来解释这种差异,或者您检测触摸的位置可能不是用户想要的位置。请注意,手指比像素大得多,并且因此,您需要在位置检测中留出很大的空间来解释这种差异,或者您检测触摸的位置可能不是用户想要的位置。它还提供事件上的位置(e.GetPosition)。它还提供事件上的位置(e.GetPosition)。