Bug? System.ArgumentException: 'unable to figure out route for:

你说的曾经没有我的故事 提交于 2021-01-05 04:48:09

问题


Error

System.ArgumentException: 'unable to figure out route for: //RegisterPage Parameter name: uri' System.ArgumentException: 'unable to figure out route for: //LogoPage Parameter name: uri'

What is wrong? It cant figure out the route...?

XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="MyApp.Views.WelcomePage"
             Shell.NavBarIsVisible="False">
    <ContentPage.Content>
        <StackLayout Padding="10,0,10,0" VerticalOptions="Center">
            <Button VerticalOptions="Center" Text="Register" Command="{Binding RegisterCommand}"/>
            <Button VerticalOptions="Center" Text="Login" Command="{Binding LoginCommand}"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

Code behind

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class WelcomePage : ContentPage
{
    public WelcomePage()
    {
        InitializeComponent();
        this.BindingContext = new WelcomeViewModel();
    }
}

WelcomeViewModel.cs

public Command RegisterCommand { get; }
public Command LoginCommand { get; }

public WelcomeViewModel()
{
    RegisterCommand = new Command(OnRegisterClicked);
    LoginCommand = new Command(OnLoginClicked);
}

private async void OnRegisterClicked(object obj)
{
    await Shell.Current.GoToAsync($"//{nameof(RegisterPage)}");
}

private async void OnLoginClicked(object obj)
{
    await Shell.Current.GoToAsync($"//{nameof(LoginPage)}");
}

回答1:


Your need to register a route for each page you are willing to navigate into it using Shell.Current.GoToAsync(), with this way you can also clarify your pages hierarchy:

    <FlyoutItem FlyoutDisplayOptions="AsMultipleItems">

        <ShellContent Title="RegisterPage"
                      Route="RegisterPage"
                      ContentTemplate="{DataTemplate local:RegisterPage}"/>

        <ShellContent Title="LoginPage"
                      Route="LoginPage"
                      ContentTemplate="{DataTemplate local:LoginPage}"/>

        <ShellContent Title="Page3"
                      ContentTemplate="{DataTemplate local:Page3}"/>

    </FlyoutItem>

You can also register the route using Routing.RegisterRoute() in the code if you prefer, as long as it runs before a route is invoked: Routing.RegisterRoute("//Page3", typeof(Page3));

Microsoft Documentation

For more details: Shell Navigation



来源:https://stackoverflow.com/questions/65002712/bug-system-argumentexception-unable-to-figure-out-route-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!