Changing page on button click in Xamarin

Newbie Dev 1 Reputation point
2021-10-11T18:16:52.77+00:00

Hello everyone,
I'm new to Xamarin;

I need to know how to switch page(view?) on button click in a .cs file, by keeping the current(custom) bottom bar and its selected icon
If I simply use:
MainPage = new xPage();
or something like
MainPage = new NavigationPage(new xPage());

The bottom bar disappears, because the main page is a type of CustomBottomBar(a custom TabbedPage)

I also tried by searching the bottom bar's button functions, and the default page used by this(which is not Xamarin Main Page but is HomePage.xaml, in Views folder), but I gone into an endless black hole since I didn't find anything about by searching keywords or references with VS.

How can I do?

I'm starting by developing a simple app by this base, you can also find the CustomBottomBar I'm using there: https://github.com/aimore/XamUI/tree/master/XamFood

Thank you in advance for the help

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kyle Wang 5,531 Reputation points
    2021-10-12T05:08:21.99+00:00

    Hi NewbieDev-7585,

    Welcome to our Microsoft Q&A platform!

    Visual Studio provides a template named "Tabbed" to achieve it. The following are the steps to create "Tabbed project".

    1. Open Visual Studio
    2. Click create a new project and select Mobile App
    3. Name the project and select template "Tabbed"

    Now you can edit the tabbar in AppShell.xaml.

    <TabBar>  
        <ShellContent Title="About" Icon="icon_about.png" Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />  
         ...  
    </TabBar>  
    

    Another workaround is that you can use ContentPresenter. For more info, you can refer to: Substitute content into a ContentPresenter.

    Regards,
    Kyle


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments