Categories
Programación

Xamarin Shell Navigation Passing Data

Xamarin Shell Navigation is one of the things I love the most from these new features. It seems to me they done a great job on this.

And one of the most usefull is passing data using query parameters. But then Navigation back became a horrible experience, and it was due to me doing a bad implementation.

Not only I was failing at doing a hierarchical navigation but the hardware button on Shell was not working. So doing some research and testing I made it work the right way.

So for this little tutorial I would use this GitHub example of Pokedex. I would use the ListView control to select a Pokemon and navigate to a Detail Page.

The main idea is to be able to use the hardware button and the back button passing data from the ListView or CollectionView. In the image below the Navigation is done hierarchically.

Xamarin Shell Navigation Passing Data.

So to do this you have to register the route during the execution of the ICommand

As you can see in the code, the Route is register to Main/Detail meaning that the stack would be order by first the Main Page and then the Detail Page. Note: The main page route was declare in the Shell Xaml. Look for it on the Github Code.

Now Xamarin Shell Navigation is done with the absolute string //Main/Detail and the parameter passed was the Item.Name, that contains the Pokemon Name.

As you can see the detail page does not contain any action for the back button, because there is no need as the Navigation was done using a new register route that was starting from Main Page.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *