Solved

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

Posted on 2014-01-22
7
327 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 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Dovberman
Comment Utility
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
Comment Utility
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
Comment Utility
Excellent, Saved 51 blocks of repeated code.
0
 
LVL 62

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Detailed instructions on how to install an Access add-in in recent versions of Office and Windows (with screen shots)
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.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now