mynameisalon
mynameisalon

Reputation: 27

Windows Phone 7: How can I do something when the user clicks on an image?

I use windows phone 7, with silverlight. 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.

Upvotes: 0

Views: 905

Answers (3)

invalidusername
invalidusername

Reputation: 913

The WP7 Silverlight Toolkit (http://silverlight.codeplex.com/) has GestureListeners where you can attach a Tap Gesture to your image and catch the event.

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

Upvotes: 1

jrb
jrb

Reputation: 1738

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

Upvotes: 4

Luke Duddridge
Luke Duddridge

Reputation: 4347

I've check all the events you can bind to an image tag, there should be one called MouseLeftButtonDown and MouseLeftButtonUp see if that gets you on the right track.

Upvotes: 0

Related Questions