Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-01-22
7
Medium Priority
?
340 Views
Last Modified: 2014-11-12
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,
0
Comment
Question by:Dovberman
  • 4
  • 3
7 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 39799889
Is this a Windows Phone app? If not what platform.

I can not find a Tap, Tap="cmdClub1_Tap", in the documentation.
0
 

Author Comment

by:Dovberman
ID: 39800057
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
        {
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 39800104
Hi Dovberman;

I have not played around with Windows Phone programming but looking at the documentation you should be able to do the following.

var theImage = e.OriginalSource as Image;

then you can read the Tag property of that Image by saying theImage.Tag

I hope that helps.

Fernando
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dovberman
ID: 39800328
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,
0
 

Author Comment

by:Dovberman
ID: 39800452
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.
0
 

Author Closing Comment

by:Dovberman
ID: 39800459
Excellent, Saved 51 blocks of repeated code.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 39800599
Glad to see that worked out for you. Have a great day.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With Windows evolving further, the built-in protective mechanisms get better and better. Still, Microsoft is not very good at introducing those to the technical community. This article is about a new bitlocker functionality that could revolutionize …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question