Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to get the Current Page Name in Tabbed Page

How to get the Current Page Name in Tabbed Page
Scenario:
1. A tabbed Page Two Tabb's where Both refers to the same Content Page with Two instance

I am trying to basically make IsVisible check while binding an element in Content Page based on which Page is in View

Answers

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Scorpian1990 - The TabbedPage has a CurrentPage property that gets the current page. The only way to distinguish which one is which is either by adding a custom property to the pages.

    e.g. you can get both pages to inherit from a new base class that inherits from ContentPage and add in the property PageId.

    But I am thinking the better approach would be triggering an event from the OnAppearing() function on the actual page to do something. Though be warned that WinPhone acts a little different (https://bugzilla.xamarin.com/show_bug.cgi?id=37008)

  • MikeDennisMikeDennis USMember ✭✭
    edited January 2016

    @AdamP tried to implement and totally confused, can you share me any working example?

  • JohnSmith.0620JohnSmith.0620 USMember ✭✭

    This is probably a little late, but for the benefit of anyone else finding this page, below is a super-simple example code:

    In your TabbedPage, put the following:

    string currentPageName = "";
    protected override void OnCurrentPageChanged()
    {
        base.OnCurrentpageChanged();
    
        currentPageName = CurrentPage.Title;
    }
    

    Every time the page changes, currentPageName gets assigned the new page's title. Within OnCurrentPageChanged(), I guess you can change whatever needs to change. For example, I change the ToolbarItems depending on which tab I have selected.

Sign In or Register to comment.