How to receive multiple parameters in the Onnavigatedto windowsPhone 8.1 event

Asked

Viewed 121 times

1

Good night I’m wearing the frame.navigate to switch pages and pass an object as parameter in windowsphone so far all quiet my doubt is how do I pass another parameter that comes from another page without problem. An error occurs because when trying to pass another parameter it falls in the first and hangs would like to know how to do the processing to differentiate the sent parameters from different pages. Example

protected override void OnNavigatedTo(NavigationEventArgs e){
    this.navigationHelper.OnNavigatedTo(e);
    if(e. tratamento que estou em duvida = objeto cliente){          

        Cliente clienteRecebido = (Cliente)e.Parameter;
        tbIdCliente.Text = Convert.ToString(clienteRecebido.idCliente);
        tbCliente.Text = clienteRecebido.razao;
        tbDataPedido.Text = "01/01/2015";

    }else if(e.tratamento que estou em duvida = objeto produto){
           //classe protudo e seus atributos etc
    }
}
  • I didn’t quite understand your doubt, you want to pass two objects by navigated to?

  • 1

    Wouldn’t it be better to use Navigationservice? But take a look here: https://social.msdn.microsoft.com/Forums/en-US/8cb42356-82bc-4d77-9bbc-ae186990cfd5/passing-parameters-during-navigation-in-windows-8?forum=winappswithcsharp using list

  • I will try to exemplify to see if I can explain better the problem

  • I’ll try to illustrate and see if I can explain the problem better. There’s a main screen with two buttons one button goes to a customer screen and another button goes to the product screen. When clicking the button to go to the customer screen appears a list with customers for the user to choose when clicking this list I return to the main screen passing as parameter a client object. Then I will choose the products click on the product search button that takes me to a screen that has a list with the products and this list when clicked on the item returns to main screen with a param obj

  • My problem is to receive this second parameter because I know that there has to be a treatment to identify what type of parameter I am receiving most know how to do this treatment. In my case Navigationservice is not working for this version I’m developing Leornado already tried and it did not work

1 answer

0


I imagine, from what you described in the comments, that you are returning the parameters correctly in the return of the page, to treat, what you should do is the following:

if (e.Parameter.GetType() == typeof(Cliente)) {
    //Faz o que deve ser feito para o cliente
} else if (e.Parameter.GetType() == typeof(Produto)) {
    //Faz o que deve ser feito com o produto
} else {
    //Recebeu um tipo não esperado
}

I hope that solves your problem.

  • 1

    Good morning Felipe. That’s exactly what I’ve been wanting to test and it worked out the way I was hoping. Thank you so much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.