locked
How I can make override for OnNavigatedTo Method for recieving 5 parameters in second page in Windows Store Application?

    Question

  • I want to transfer 2 strings, 2 brush element and along with opening next blank page... Please tell me how I can make a 5 parameters override OnNevigatedTo override in second blank page to recieve these parameters . Or there is any other efficient way then please tell me that. Thank You!


    Wednesday, May 28, 2014 3:56 AM

Answers

  • Hi,

    You cannot pass more than one parameter to the other page by use of NavigateTo method. But you can make these parameter contain in a class, and then pass the class object to the next page. Define a class like below:

    public class student
        {
            public String name { get; set; }
            public int roll { get; set; }
        }
    
     

    In Main Page:

    private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                student s1= new student();
                s1.name="abc";
                s1.roll=10;
    
                this.Frame.Navigate(typeof(BlankPage1), s1);
            }

    The target page:

    protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                student p = e.Parameter as student;
                if (p.name != null)
                {
                }
    
            }

    And you can refer to the link to see how to navigate between page:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, May 29, 2014 2:40 AM

All replies

  • as much as i know you can not do that but i may be mistaken, yet the most common way to transfer more than one parameter is quiet easy, simply all you need to do is to instantiate an object that would hold all your parameters and send it to the page.

    result 1 object, a lot of data.

    receive and decode the object in the LoadState function in the target page

    for example i want to move 2 strings i would make this class

    public Class ParamObject { string s1 {get; set;} string s2 {get; set;} public ParamObject(string ss1, string ss2){

    this.s1 = ss1;

    this.s2 = ss2;

    } }


    lets say that you want to navigate from a page after clicking an object in a gridview on the first page

    public void itemsGridView_itemClick(Sender s, clickedItem e)
    {
    MyType clicked = e.clickedItem as MyType;
    ParamObject p = new ParamObject(clicked.string1, clicked.string2);
    this.Frame.NavigateTo(TypeOf(TargetPage),p);
    }

    and handle the ParamObject in the TargetPage as:

    public void TargetPage_LoadState(State args,NavigationParameter e)
    {
    ParamObject p = e.NavigationParameter as ParamObject;
    
    // now in here you can use whatever you want p with
    // example setting 2 buttons content
    bt1.content = p.s1;
    bt2.content = p.s2;
    }

    regards,

    Wednesday, May 28, 2014 5:05 AM
  • realize when using complex object the SuspenionManager (if using) will crash. What you can do is serialize the object and send the string, in the page you opening you need to deserialize the data again

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, May 28, 2014 6:11 AM
  • Hi,

    You cannot pass more than one parameter to the other page by use of NavigateTo method. But you can make these parameter contain in a class, and then pass the class object to the next page. Define a class like below:

    public class student
        {
            public String name { get; set; }
            public int roll { get; set; }
        }
    
     

    In Main Page:

    private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                student s1= new student();
                s1.name="abc";
                s1.roll=10;
    
                this.Frame.Navigate(typeof(BlankPage1), s1);
            }

    The target page:

    protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                student p = e.Parameter as student;
                if (p.name != null)
                {
                }
    
            }

    And you can refer to the link to see how to navigate between page:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, May 29, 2014 2:40 AM