Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

Is there a way to determine which object has been tapped?

I have a grid that has 52 cells (4 rows, 13 columns).  There is an image in each cell.

I would like to set the same tap event for each of the 52 images.

<Image x:Name="imgClub1"
                Width ="28"
                Source="Images\C1Clip.png"
                Height="40"
                Grid.Row="0"
                Grid.Column="0" Stretch="None"
                Margin="0,0,28,0"
                Tag="C1Full"
                Tap="cmdClub1_Tap"
                Grid.ColumnSpan="2" VerticalAlignment="Top"
               />

            <Image x:Name="imgClub2"
                     Width ="28" Source="Images\C2Clip.png"
                     Height="40"
                     Grid.Row="0"
                     Grid.Column="1" Stretch="None"
                     Margin="0,0,0,0"
                     Tag="C2Full"
                     VerticalAlignment="Top"
                     Tap="cmdClub1_Tap"
                />

void cmdClub1_Tap(object sender,
                     System.Windows.Input.GestureEventArgs e)
        // Place selected image into imgHole
        {
            //string strImageName = TappedImage.Tag.ToString();
How do I determine the name of the tapped image?

Is there a Selected property for images?

Thanks,
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Is this a Windows Phone app? If not what platform.

I can not find a Tap, Tap="cmdClub1_Tap", in the documentation.
Avatar of Dovberman

ASKER

This is a Windows Phone 8 app running on Windows 8.0 Pro.

Tap="cmdClub1_Tap" declares the Tap event. This is like the OnClick property that can be set in asp.net.

Debugging allows me to step through the void cmdClub1_Tap(object sender,
                     System.Windows.Input.GestureEventArgs e)
        // Place selected image into imgHole
        {
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This would indicate that the Image source of the tapped image can be saved as an event property.  I will try that.

Phone programming exposes a lot of properties and events. This is an exciting new platform for me after spending 10 years developing web sites.

Thanks,
Yes this works,

void cmdClub1_Tap(object sender,
                     System.Windows.Input.GestureEventArgs e)
     
   // Place selected image into imgHole

            var imgTapped = e.OriginalSource as Image;  // The image that was tapped.
           
            imgHole1.Source = imgTapped.Source;    // Copies the tapped image

-----
All 52 images use the same event procedure, ( cmdClub1_Tap), To be renamed cmdClip_Tap.

This saves repeating a code block 51 times.
Excellent, Saved 51 blocks of repeated code.
Glad to see that worked out for you. Have a great day.