我正在尋找“匹配的模糊路線”問題的解決方案。我在 AppShell.xaml.cs 中注冊了路由:
Routing.RegisterRoute("dashboard", typeof(DashboardPage));
Routing.RegisterRoute("wholesalers", typeof(WholesalersPage));
Routing.RegisterRoute("newOrder", typeof(NewOrderPage));
Routing.RegisterRoute("products", typeof(ProductsPage));
Routing.RegisterRoute("products/add", typeof(ProductAddPage));
在 ProductAddViewModel.cs 中呼叫命令后
private async void OpenBarcodeReader()
{
scanPage = new ZXingScannerPage();
scanPage.OnScanResult = (result) =>
{
scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(async () =>
{
try
{
await Navigation.PopModalAsync();
}
catch (Exception ex)
{
var theproblem = ex;
}
Product.EAN = result.Text;
});
};
await Navigation.PushModalAsync(scanPage);
}
我收到一個錯誤:
Ambiguous routes matched for:
//D_FAULT_TabBar10/D_FAULT_Tab9/products/D_FAULT_ProductAddPage11
matches found:
//D_FAULT_TabBar10/D_FAULT_Tab9/products/D_FAULT_ProductAddPage11,
//D_FAULT_TabBar10/D_FAULT_Tab9/products/D_FAULT_ProductAddPage11
Parameter name: uri
我不明白的是:
a)為什么我會收到此錯誤:D
b) 如果 PushModalAsync 執行正確(出現條碼閱讀器頁面,result.Text 正確分配給 Product.EAN),那為什么我不能執行 await Navigation.PopModalAsync(); ?
我查看了有關 MS Docs 的檔案,但我認為我的大腦已經沸騰了 :-S
uj5u.com熱心網友回復:
設定路由時,如果頁面位于 Shell 視覺層次結構中,請在 xaml 中設定路由。
<Shell ...> <FlyoutItem ... Route="animals"> <ShellContent ... Route="monkeys" /> </FlyoutItem> </Shell>如果頁面不在 Shell 視覺層次結構中,請將其設定為
Routing.RegisterRoute. 僅使用 XAML 或 C#注冊一次路由,而不是同時使用兩者。當您在 Shell 中進行導航時,您可以使用
Shell.Current.GoToAsync絕對路由,如下面的代碼。await Shell.Current.GoToAsync("//animals/monkeys");有關更多詳細資訊,您可以參考 MS 檔案: https ://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#absolute-routes
如果這個問題仍然存在,您能否將您的演示分享到 GitHub,然后在此處發布鏈接。我將幫助您進行進一步的故障排除。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/496187.html
標籤:C# xamarin 虚拟机 xamarin.forms.shell
上一篇:在.NetMAUI中獲取AndroidCurrentActivity
下一篇:將視頻從Xamarin應用上傳到azureblob商店。6次嘗試后重試失敗。重試設定可以在ClientOptions.Retry中調整
