【发布时间】:2019-10-12 09:53:59
【问题描述】:
在 Xamari.Forms 中,我在 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"/>
在 AppShell.xaml.cs 中,我以编程方式为 Toolbox 页面添加了上下文页面导航:
public AppShell ()
{
InitializeComponent ();
Routing.RegisterRoute("Toolbox/TBOuvriers", typeof(TBOuvriers));
BindingContext = this;
}
当我尝试从工具箱页面显示上下文页面导航时:
await Shell.Current.GoToAsync("//Main/Toolbox/TBOuvriers");
我得到了这个异常:
System.ArgumentException:不明确的路线匹配://Main/Toolbox/TBOuvriers 找到匹配项:
//主/工具箱/TBOuvriers/TBOuvriers,
//Main/IMPL_Toolbox/Toolbox/TBOuvriers
参数名称:uri
就在调用之前,我可以看到 Shell 变量的值:
Shell.Current.CurrentItem : "Title = Toolbox, Route = Main"
Shell.Current.CurrentState.Location : "{//Main/Toolbox}"
这似乎是预期的。
如果我尝试使用此调用显示页面:
await Shell.Current.GoToAsync("TBOuvriers");
我也得到一个异常:System.Exception: Timeout exceeded getting exception details
那么,问题出在哪里?
这些路线来自哪里?!?
为什么工具箱页面被注册了2次?
欢迎所有想法!
最好的问候
【问题讨论】:
-
进一步查看网络上的文章,我发现人们主要将新页面(如上下文页面)声明为全局,但它们没有出现在 fyout 菜单中。如果我这样做,它对我有用。像在 xamarin shell 文档中一样将它们声明为现有页面的子页面(如在我的主题中)有问题吗?
-
同样的观察:在 Xanimals 演示项目中,他们使用
"Routing.RegisterRoute("monkeydetails", typeof(MonkeyDetailPage));"而不是"Routing.RegisterRoute("monkey/details", typeof(MonkeyDetailPage));"为什么?调用 "await Shell.Current.GoToAsync("details") 应该更容易;" 来自每个动物页面,而不是 "await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?name={animalName}");"跨度> -
,你可以在你的项目中尝试这种方式,这里有什么问题吗?
-
我做的和 XAnimals 一样。我所有的独立页面都在根目录中注册。但我无法成功应用他们在官方文档中提出的方式。所以,对我有用,但也许不是最好的方法。
-
如果你有更好的方法解决这个问题,请在这里分享,谢谢。
标签: forms shell xamarin routes