漏洞?System.ArgumentException:'无法找出以下路线: [英] Bug? System.ArgumentException: 'unable to figure out route for:

查看:105
本文介绍了漏洞?System.ArgumentException:'无法找出以下路线:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误

System.ArgumentException:'无法找出以下路线://RegisterPage参数名称:uri'System.ArgumentException:'不可用找出以下路线://LogoPage参数名称:uri'

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>

后面的代码

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

WelcomeViewModel.cs

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)}");
}

推荐答案

您需要使用 Shell.Current.GoToAsync()为愿意浏览的每个页面注册一个路由,并使用这样,您还可以阐明页面层次结构:

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>

如果愿意,还可以在代码中使用 Routing.RegisterRoute()注册路由,只要它在调用路由之前运行即可: Routing.RegisterRoute("//Page3",typeof(Page3));

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));

更多详细信息: Shell导航

这篇关于漏洞?System.ArgumentException:'无法找出以下路线:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆