xamarin.forms - 带有 Shell 的 Xamarin 表单:更改 MainPage
问题描述
我正在尝试更改我的 MainPage,根据我的 RadioButton Group 中标记的页面,在我的设置中。因此,如果标记第一个将是“APage”,否则,“BPage”。但是当我尝试更改MainPage = new AppShell();
它时,只需忽略并且不要转到另一页。我的标准 MainPage 注册为:
<ShellContent Title="{x:Static resource:AppResources.home}" Icon="home_icon.png" Route="MainPage" ContentTemplate="{DataTemplate local:MainPage}" />
,但我试图删除它Route
并执行以下操作:
DatabaseAccess DAO = new DatabaseAccess();
if (Convert.ToInt32(DAO.GetRadioValue()[0].RadioButtonValue) == 1)
category.Route = "MainPage";
else
home.Route = "MainPage";
但它仍然不起作用。即使我去我的标准 MainPage 的代码隐藏并且Shell.Current.GoToAsync(nameof(CategoryPage));
什么都不做。
有任何想法吗?
解决方案
您可以<ShellContent ... Route="xxx" />
在 xaml 页面上使用或Routing.RegisterRoute("xxx", typeof(xxx));
在 cs 页面上使用来注册 Route。
然后检查您的DAO.GetRadioValue()[0].RadioButtonValue
值并await Shell.Current.GoToAsync("xxx");
用于页面跳转。
您可以查看此链接 ( https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation ) 了解更多信息。