question

NewbieDev-7585 avatar image
0 Votes"
NewbieDev-7585 asked RobCaplan edited

Changing page on button click in Xamarin

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

dotnet-xamarinforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleWang-MSFT avatar image
0 Votes"
KyleWang-MSFT answered KyleWang-MSFT edited

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.