locked
Passing parameter while navigation RRS feed

  • Question

  • Hi,

    i wanted to know if i am navigating from a small grid which contains images and text, to another page by tapping on the grid, how can i pass the textbox text or even the grid name as a parameter to be shown in next page?

    thankyou

    Wednesday, May 15, 2013 4:55 PM

Answers

  • This is already there in Grid project template of VS 2012. On GridView ItemClick event you can have an event handler

    /// <summary>
    /// Invoked when an item is clicked.
    /// </summary>
    /// <param name="sender">The GridView (or ListView when the application is snapped)
    /// displaying the item clicked.</param>
    /// <param name="e">Event data that describes the item clicked.</param>
    void ItemView_ItemClick(object sender, ItemClickEventArgs e)
    {
        // Navigate to the appropriate destination page, configuring the new page
        // by passing required information as a navigation parameter
        var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;
        this.Frame.Navigate(typeof(ItemDetailPage), itemId);
    }

    In place of itemId you may wish to use

    this.Frame.Navigate(typeof(ItemDetailPage), (sender as GridView).Name);

    On the other page  where you navigate you can override OnNavigatedTo event and get the passed parameter

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (e != null && e.Parameter != null && e.Parameter is string)
        {
            string passesedName = e.Parameter as string;
        }
    
        base.OnNavigatedTo(e);
    }

    • Marked as answer by Amnz Friday, May 17, 2013 4:35 PM
    Wednesday, May 15, 2013 5:09 PM
  • In my reply you could see

    var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;

    Now if SapleDataItem has a property called TextData you can get that as

    var text = ((SampleDataItem)e.ClickedItem).TextData;
    this.Frame.Navigate(typeof(ItemDetailPage), text;

    In XAML this TextBlock would be something like

    <TextBlock Text={Binding TextData}/>

    --------------------------------------------------------------

    If you find my response helpful then please do not  forget to mark them as Answer and Helpful!

    • Marked as answer by Amnz Friday, May 17, 2013 4:35 PM
    Thursday, May 16, 2013 8:41 AM

All replies

  • This is already there in Grid project template of VS 2012. On GridView ItemClick event you can have an event handler

    /// <summary>
    /// Invoked when an item is clicked.
    /// </summary>
    /// <param name="sender">The GridView (or ListView when the application is snapped)
    /// displaying the item clicked.</param>
    /// <param name="e">Event data that describes the item clicked.</param>
    void ItemView_ItemClick(object sender, ItemClickEventArgs e)
    {
        // Navigate to the appropriate destination page, configuring the new page
        // by passing required information as a navigation parameter
        var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;
        this.Frame.Navigate(typeof(ItemDetailPage), itemId);
    }

    In place of itemId you may wish to use

    this.Frame.Navigate(typeof(ItemDetailPage), (sender as GridView).Name);

    On the other page  where you navigate you can override OnNavigatedTo event and get the passed parameter

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (e != null && e.Parameter != null && e.Parameter is string)
        {
            string passesedName = e.Parameter as string;
        }
    
        base.OnNavigatedTo(e);
    }

    • Marked as answer by Amnz Friday, May 17, 2013 4:35 PM
    Wednesday, May 15, 2013 5:09 PM
  • Thank you so much..
    it works perfectly..

    i also wanted to know if there is any way i can pass the textblock text when tapped on the grid it is contained in??
    Wednesday, May 15, 2013 6:55 PM
  • In my reply you could see

    var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;

    Now if SapleDataItem has a property called TextData you can get that as

    var text = ((SampleDataItem)e.ClickedItem).TextData;
    this.Frame.Navigate(typeof(ItemDetailPage), text;

    In XAML this TextBlock would be something like

    <TextBlock Text={Binding TextData}/>

    --------------------------------------------------------------

    If you find my response helpful then please do not  forget to mark them as Answer and Helpful!

    • Marked as answer by Amnz Friday, May 17, 2013 4:35 PM
    Thursday, May 16, 2013 8:41 AM
  • Thanks Alot :)
    that was totally helpful
    Friday, May 17, 2013 4:35 PM