locked
how can i know which textblock tapped ?? RRS feed

  • Question

  • Hi there

    i want to know which textblock tapped, i mean in a tap event  i get the name of the textblock .

    that is my xaml " textblock in grid "

            <TextBlock  Grid.Column="0" Grid.Row="1" Tag="A" Tap="choix_tap"/>
            <TextBlock  Grid.Column="1" Grid.Row="1" Tag="B" Tap="choix_tap" />
            <TextBlock  Grid.Column="0" Grid.Row="2" Tag="C" Tap="choix_tap" />
            <TextBlock  Grid.Column="1" Grid.Row="2" Tag="D" Tap="choix_tap"/>
        
    

    and here what i want to do 

    private void choix_tap(object sender, System.Windows.Input.GestureEventArgs e)
            {
                
               // get the name or id of the tapped textblock 
    
            }

    thank you 

    Thursday, March 6, 2014 11:23 AM

Answers

  • private void choix_tap(object sender, System.Windows.Input.GestureEventArgs e) { TextBlock tempVar = (TextBlock) sender; tempVar.tag; //Gives you the tag of the text box }

    Uee type casting and convert it back to your object and get the Tag value.

    Rahber
    @Rahber

    • Marked as answer by chinigami Thursday, March 6, 2014 12:30 PM
    Thursday, March 6, 2014 12:20 PM

All replies

  • private void choix_tap(object sender, System.Windows.Input.GestureEventArgs e) { TextBlock tempVar = (TextBlock) sender; tempVar.tag; //Gives you the tag of the text box }

    Uee type casting and convert it back to your object and get the Tag value.

    Rahber
    @Rahber

    • Marked as answer by chinigami Thursday, March 6, 2014 12:30 PM
    Thursday, March 6, 2014 12:20 PM
  • thank you Rahber  you helped me .
    Thursday, March 6, 2014 12:31 PM