【问题标题】:Xamarin Forms with Shell: Change MainPage带有 Shell 的 Xamarin 表单:更改 MainPage
【发布时间】:2021-10-27 21:25:30
【问题描述】:

我正在尝试更改我的 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)); 什么也不做。

有什么想法吗?

【问题讨论】:

    标签: xamarin.forms routes xamarin.forms.shell app-shell


    【解决方案1】:

    你可以在xaml页面使用<ShellContent ... Route="xxx" />或者在cs页面使用Routing.RegisterRoute("xxx", typeof(xxx));注册Route。

    然后检查您的DAO.GetRadioValue()[0].RadioButtonValue 值并使用await Shell.Current.GoToAsync("xxx"); 进行页面跳转。

    您可以查看此链接 (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation) 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 2022-01-27
      相关资源
      最近更新 更多