locked
How can i pass a parameter in tap even RRS feed

  • Question

  •         

           Hi , please help me , i want to pass a parameter in a tap event , but i work just with the code bihind and i my code is like that. 





     Deployment.Current.Dispatcher.BeginInvoke(() =>
                     {

    Dispatcher.BeginInvoke(() => title.Text = art.title); article_presentation.Tap += StackPanel_Tap;

    } private void StackPanel_Tap(object sender, GestureEventArgs e) { NavigationService.Navigate(new Uri("/Article_complet.xaml?id=" + "here passing art.title", UriKind.Relative)); }




           
    Wednesday, February 19, 2014 3:19 PM

Answers

  • No, that's not going to work.  Do this:

    article_presentation.Tap += StackPanel_Tap; article_presentation.Tag = "message" }

    private void StackPanel_Tap(object sender, GestureEventArgs e) { string tag = (string) ((StackPanel)sender).Tag; NavigationService.Navigate(new Uri("/Article_complet.xaml?id=" + "here passing art.title", UriKind.Relative)); }



    Darin R.


    • Edited by Darin Rousseau Thursday, February 20, 2014 2:26 PM bad formatting
    • Marked as answer by chinigami Thursday, February 20, 2014 3:29 PM
    Thursday, February 20, 2014 2:25 PM

All replies

  • Can you provide a XAML code?
    Wednesday, February 19, 2014 4:06 PM
  • //I generate element dynamically in here i don't use xaml

    try { foreach (Article art in list_article) if (art != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { StackPanel article_presentation = new StackPanel(); StackPanel sous_article_presentation = new StackPanel(); textblock title= new textblock (); Dispatcher.BeginInvoke(() => title.Text = art.title); sous_article_presentation.Children.Add(title); article_presentation.Children.Add(sous_article_presentation); root_panel.Items.Add(article_presentation);//<ListBox x:Name="root_panel"> in xaml article_presentation.Tap += StackPanel_Tap;//here i want send the parameter title }); } } catch (Exception e) { MessageBox.Show("erreur : " + e); } } } private void StackPanel_Tap(object sender, GestureEventArgs e) { NavigationService.Navigate(new Uri("/Article_complet.xaml?id=" + "here the parameter send ", UriKind.Relative)); } }




    • Edited by chinigami Wednesday, February 19, 2014 4:24 PM
    Wednesday, February 19, 2014 4:15 PM
  • Make your "art" variable as global in your class and then you can call it from anywhere within that class.
    Wednesday, February 19, 2014 7:19 PM
  • Add the title (or any other object) to the .Tag Parameter of the button or Link or object being tapped. 

    When the item is tapped, look at the sender in the parameters, and get the tag of the sender.  You may have to cast the sender to your object type.  For example, a button:

    var param = ((Button) sender). Tag;

    param now contains the object you set earlier in the constructor.


    Darin R.

    Thursday, February 20, 2014 2:56 AM
  • Dear mcosmin  : thank you but i can not do that , the art is declared inside a methode .

    Dear Darin Rousseau  : that is the idea  i will do it , but  can i  do like that ??  : 

    article_presentation.Tap += StackPanel_Tap(art.id , ???   );   // first argument accepted but the second i don't know what can i do 

    Thursday, February 20, 2014 9:14 AM
  • No, that's not going to work.  Do this:

    article_presentation.Tap += StackPanel_Tap; article_presentation.Tag = "message" }

    private void StackPanel_Tap(object sender, GestureEventArgs e) { string tag = (string) ((StackPanel)sender).Tag; NavigationService.Navigate(new Uri("/Article_complet.xaml?id=" + "here passing art.title", UriKind.Relative)); }



    Darin R.


    • Edited by Darin Rousseau Thursday, February 20, 2014 2:26 PM bad formatting
    • Marked as answer by chinigami Thursday, February 20, 2014 3:29 PM
    Thursday, February 20, 2014 2:25 PM
  • Darin Rousseau : thank you very much you saved me in that issue

    Thursday, February 20, 2014 3:29 PM