'ListView navigation using Xamarin.Forms Shell

I am trying to figure out how to make my application a Shell application.

This is my shell.xaml.

<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   xmlns:views="clr-namespace:Project.View"
   x:Class="Project.AppShell">
<ShellContent Title=""
              ContentTemplate="{DataTemplate views:MainPage}"/>
<ShellContent Title=""
             ContentTemplate="{DataTemplate views:ListView}" 
              Route="StockListView"/>

</Shell>

I am having trouble to make sense of the routing, my goal is to make routing from the listview to another view, like below.

MainView
ListView
    ViewItem

I don't find it clear how to implement this, since the listview is not one of the three main hierachical objects, at least not obvious for me. https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/introduction . I can get it to work by changing the page from my viewmodel that is connected to my listview.

App.Current.Mainpage = View

But it feels like I am mixing things up and that it should be possible to use Shell routing in some way, is this possible?



Solution 1:[1]

  1. First you need to register the route, you can register the route in the xaml page or register the route in the back-end code.

    For more information you can refer to: Register routes.

  2. After registering the route you can use await Shell.Current.GoToAsync("//ListView/ViewItem"); code to make the call elegantly.

    Please take care of the use of routes multiple levels(route hierarchy).

    For the detailed usage of route navigation, you can check: Perform navigation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1