question

jokertn avatar image
0 Votes"
jokertn asked jokertn commented

Switch between tappedPage Xamarin Forms

Hello ,
I have this xaml code (main Page):


 <?xml version="1.0" encoding="UTF-8"?>
     <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
                  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:Test.Views.Food"
        
                              x:Class="Test.Views.Food.OrderFood"
                                 xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
         android:TabbedPage.ToolbarPlacement="Bottom"
     >
        
        
         <local:Menu></local:Menu>
         <local:OrderForm></local:OrderForm>
                       
     </TabbedPage>

and in the Menu Page there is also a tappebPage :

     <?xml version="1.0" encoding="UTF-8"?>
     <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
                  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                  x:Class="Test.Views.Food.Menu"
                  Title="Menu"
                  xmlns:local="clr-namespace:Test.Views.Food"
                  x:Name="_menu"
                  xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
         android:TabbedPage.ToolbarPlacement="Bottom">
        
         <local:Page1></local:Page1>
         <local:Page2></local:Page2>
        
        
        
     </TabbedPage>


and in my page1 i have button(btn1), when i click it suppose to switch to OrderFrom

my code when i press on btn1:

         private void Btn1Click(object sender, EventArgs e)
         {
             var masterPage = this.Parent as TabbedPage;
             masterPage.CurrentPage = masterPage.Children[1];
    
         }

this code work fine, but he switch between page 1 and page 2 , but my objective to switch to OrderForm.
thanks i advance.





dotnet-xamarin
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
1 Vote"
KyleWang-MSFT answered jokertn commented

Hi jokertn,

Welcome to our Microsoft Q&A platform!

var masterPage = this.Parent as TabbedPage;

In the code above, the key word "this" refers to "Page1". So when you call "this.Parent", you will get the instance of "Menu".

To switch to "OrderForm", you need to get the instance of Menu's parent. So try to modify the code as follows.

 private void Btn1Click(object sender, EventArgs e)
 {
     var masterPage = this.Parent.Parent as TabbedPage;
     masterPage.CurrentPage = masterPage.Children[1];
 }

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.

· 1
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.

thank you
it works.

0 Votes 0 ·