Xamarin Shell引发不明确的路由匹配异常

wa7juj8i  于 2022-12-07  发布在  Shell
关注(0)|答案(2)|浏览(152)

In Xamari.Forms, I use the following route declaration in AppShell.xaml :

<FlyoutItem Title = "Toolbox"
             FlyoutDisplayOptions="AsMultipleItems"
             Route="Main">

      <ShellContent Title = "Toolbox"
                    ContentTemplate="{DataTemplate Views:Toolbox}"
                    Route="Toolbox"/>

 </FlyoutItem>

 <ShellContent Title = "Parameters"
               ContentTemplate="{DataTemplate Views:Parameters}"
               Route="Parameters"/>

In the AppShell.xaml.cs, I add programatically a contextual page navigation for the Toolbox page:

public AppShell ()
{
    InitializeComponent ();

    Routing.RegisterRoute("Toolbox/TBOuvriers", typeof(TBOuvriers));

    BindingContext = this;
}

When I try to display the contextual page navigation from the Toolbox Page:

  • await Shell.Current.GoToAsync("//Main/Toolbox/TBOuvriers");*

I get this Exception :
System.ArgumentException: Ambiguous routes matched for: //Main/Toolbox/TBOuvriers matches found:
//Main/Toolbox/TBOuvriers/TBOuvriers,
//Main/IMPL_Toolbox/Toolbox/TBOuvriers
Parameter name: uri
Just before the call, I can see those values for the Shell variables :

  • Shell.Current.CurrentItem : "Title = Toolbox, Route = Main"

Shell.Current.CurrentState.Location : "{//Main/Toolbox}"*

Which seem to be the expected one's.

If I try to display the page with this call:

  • await Shell.Current.GoToAsync("TBOuvriers");*

I also get an Exception : System.Exception: Timeout exceeded getting exception details
So, What's the problem ?
Where does those routes come from ?!?
Why is the Toolbox page 2 times registered ?
All ideas are welcome !
Best regards

zf2sa74q

zf2sa74q1#

对于任何人,将面临这个问题,并有这个错误信息太;
System.ArgumentException:'匹配的路由不明确:...'
当您在XAML中注册路由(在appshell文件中),并且还尝试在C#的代码隐藏中注册路由时,会发生这种情况。请仅使用XAML或C#注册路由一次,而不要同时使用两者。

gfttwv5a

gfttwv5a2#

如果你有2个注册无论什么原因尝试:

<Tab Title="Groups">    
    <ShellContent Route="HomeTab"  ContentTemplate="{DataTemplate local:Home}" />
</Tab>

然后在代码中

Routing.RegisterRoute("Home", typeof(Home)))

根据您的导航,您可能希望尝试:

await Shell.Current.GoToAsync("//HomeTab", true);

await Shell.Current.GoToAsync("//Home", true);

PS我讨厌AppShell导航

相关问题