gpt4 book ai didi

c# - 漏洞? System.ArgumentException : 'unable to figure out route for:

转载 作者:行者123 更新时间:2023-12-03 21:45:02 32 4
gpt4 key购买 nike

错误

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


怎么了?它无法弄清楚路线......?
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();
}
}
欢迎 View 模型.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() 为您愿意导航的每个页面注册一个路由,通过这种方式,您还可以阐明您的页面层次结构:

    <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));微软文档
更多详情: Shell Navigation

关于c# - 漏洞? System.ArgumentException : 'unable to figure out route for:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65002712/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com