locked
How to open master page from tabbed bar RRS feed

  • Question

  • User382401 posted

    How to open the master page from the tabbed bar more button

    Sunday, December 6, 2020 2:33 PM

Answers

  • User369978 posted

    Create a global variable to remember which page is selected previously .

    Reset the CurrentPage if you tap on the more tab.

    ``` Page lastPage; public TabbedPage1() { InitializeComponent();

            lastPage = Children[0];
    
    
            this.CurrentPageChanged += (sender, e)=> {
    
                var index = this.Children.IndexOf(CurrentPage);
                if (index == 3)
                {
                    this.CurrentPage = lastPage;
                }
    
                lastPage = CurrentPage;
            };       
        }
    

    ```

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, December 8, 2020 5:46 AM

All replies

  • User369978 posted

    Hi , @KKA May I ask are you developing standard Forms project or Shell project ?


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    Monday, December 7, 2020 8:28 AM
  • User382401 posted

    standard Forms project

    Monday, December 7, 2020 8:49 AM
  • User369978 posted

    Enable IsPresented of the MasterDetailPage in CurrentPageChanged method in TabbedPage. (send the messaging center or something else).

    ``` public TabbedPage1() { InitializeComponent();

            this.CurrentPageChanged += (sender, e)=> { 
                //open the master detail page
            };
    
    
        }
    

    ```

    Monday, December 7, 2020 8:54 AM
  • User382401 posted

    I want after click on more tap to open the master , without change page , how to write this in tab bar ?

    Monday, December 7, 2020 8:58 AM
  • User369978 posted

    Tabbedpage

    ``` public TabbedPage1() { InitializeComponent();

            this.CurrentPageChanged += (sender, e)=> {
    
                var index = this.Children.IndexOf(CurrentPage);
                if(index == 3)
                {
                    MessagingCenter.Send<object>(this, "Hi");
                }
    
            };
        }
    

    ```

    Master detail Page

    ``` public MasterPage() { InitializeComponent();

            MessagingCenter.Subscribe<object>(this,"Hi",(o)=>{
                this.IsPresented = true;
            });
        }
    

    ```

    Monday, December 7, 2020 9:05 AM
  • User382401 posted

    Thank you @ColeX its work , but what i want to stay in the page and open the master without move to next page

    Monday, December 7, 2020 9:57 AM
  • User369978 posted

    Create a global variable to remember which page is selected previously .

    Reset the CurrentPage if you tap on the more tab.

    ``` Page lastPage; public TabbedPage1() { InitializeComponent();

            lastPage = Children[0];
    
    
            this.CurrentPageChanged += (sender, e)=> {
    
                var index = this.Children.IndexOf(CurrentPage);
                if (index == 3)
                {
                    this.CurrentPage = lastPage;
                }
    
                lastPage = CurrentPage;
            };       
        }
    

    ```

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, December 8, 2020 5:46 AM
  • User382401 posted

    it's work for iOS doesn't work for Android .

    Tuesday, December 8, 2020 11:03 PM
  • User369978 posted

    @KKA said: it's work for iOS doesn't work for Android .

    What is not work ? Could you elaborate more about the problem ?

    Wednesday, December 9, 2020 9:21 AM
  • User382401 posted

    when I click on the tabbed page in Android the app crush . (without Errors ) when I check the index of page to understand what the problem I see the index
    index=2 index=0 index=2 index=0 index=2 index=0 index=2 index=0........and crush !

    Wednesday, December 9, 2020 4:53 PM
  • User369978 posted

    @KKA said: when I click on the tabbed page in Android the app crush . (without Errors ) when I check the index of page to understand what the problem I see the index
    index=2 index=0 index=2 index=0 index=2 index=0 index=2 index=0........and crush !

    This looks like a dead loop , set CurrentPage would trigger CurrentPageChanged event .

    But it's wired I also test on Android it's working fine , would you mind sharing us a basic ,minimal project to reproduce the problem ?

    Thursday, December 10, 2020 7:58 AM
  • User382401 posted

    lastPage = t1.Children[0];

            this.t1.CurrentPageChanged += (sender, e) => {
    
                var index = this.t1.Children.IndexOf(t1.CurrentPage);
               //Console.WriteLine("index=" + index);
    
                if (index == 2)
                {
                    this.t1.CurrentPage = lastPage;
                    this.IsPresented = true;
    
                }
                else lastPage = t1.CurrentPage;
            };
    
    Thursday, December 10, 2020 12:46 PM
  • User382401 posted

    t1 is the tabbed page in masterdetialpage

    Thursday, December 10, 2020 12:47 PM
  • User369978 posted

    I use your code it works fine , pls check my sample .

    Friday, December 11, 2020 3:02 AM