Solved

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

Posted on 2014-01-22
7
330 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 63

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 63

Accepted Solution

by:
Fernando Soto earned 500 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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 63

Expert Comment

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Detailed instructions on how to install an Access add-in in recent versions of Office and Windows (with screen shots)
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.

820 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