Solved

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

Posted on 2014-01-22
7
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

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)

Question has a verified solution.

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

Security measures require Windows be logged in using Standard User login (not Administrator).  Yet, sometimes an application has to be run “As Administrator” from a Standard User login.  This paper describes how to create a shortcut icon to launch a…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

752 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