Xamarin Forms with Shell: Change MainPage

1.3k Views Asked by At

I'm trying to change my MainPage, according to which page are marked in my RadioButton Group, in my settings. So if is marked the first will be "APage", else, "BPage". But when I try to change MainPage = new AppShell(); it just ignore and don't go to another page. My standard MainPage is registered as:

<ShellContent Title="{x:Static resource:AppResources.home}" Icon="home_icon.png" Route="MainPage" ContentTemplate="{DataTemplate local:MainPage}" />, but I tried to remove this Route and do something like this:

DatabaseAccess DAO = new DatabaseAccess();

if (Convert.ToInt32(DAO.GetRadioValue()[0].RadioButtonValue) == 1)
   category.Route = "MainPage";
else
   home.Route = "MainPage";         

but it still doesn't work. Even if I go to the code-behind of my standard MainPage and put Shell.Current.GoToAsync(nameof(CategoryPage)); do nothing.

Any ideas?

1

There are 1 best solutions below

0
On

You can use <ShellContent ... Route="xxx" /> on the xaml page or use Routing.RegisterRoute("xxx", typeof(xxx)); on the cs page to register Route.

Then check your DAO.GetRadioValue()[0].RadioButtonValue value and use await Shell.Current.GoToAsync("xxx"); for page jump.

You can check this link (https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation) for more information.