Content-Page OnAppearing-Event fired too early

Hello,

I have normal TabbedPage:

<TabbedPage.Children>
    <NavigationPage Title="Page1">
        <x:Arguments>
            <views:Page1 />
        </x:Arguments>
    </NavigationPage>

    <NavigationPage Title="Page2">
        <x:Arguments>
            <views:Page2 />
        </x:Arguments>
    </NavigationPage>

....

</TabbedPage.Children>

Expected Behaviour:
When I touch Page2, I expect to get an OnAppearing-Event.

Actual (bug?) Behaviour:
When the app starts, OnAppearing-Events are immidiatly fired for all NavigationPages (Content-Page1,Content-Page2,..).
When I touch on Page2, no OnAppearing gets fired. When I touch Page3, then OnDisappearing gets fired and afterwards, when touching Page2, I get the desired OnAppearing only directly when I open the page (so my code fails on first open of page and works on re-open).

How can I get a delayed event, that only gets fired, when I really touch the Tab-Page2.

Best Answer

  • HarshitaHarshita IN ✭✭✭✭
    Accepted Answer

    @frankme
    Use OnCurrentPageChanged() method instead of OnAppearing Inside your Tabbed Content Page
    protected override void OnCurrentPageChanged()
    {
    GlobalVariables.selectedTabIndex = this.Children.IndexOf(this.CurrentPage);
    }

Answers

  • HarshitaHarshita INMember ✭✭✭✭
    Accepted Answer

    @frankme
    Use OnCurrentPageChanged() method instead of OnAppearing Inside your Tabbed Content Page
    protected override void OnCurrentPageChanged()
    {
    GlobalVariables.selectedTabIndex = this.Children.IndexOf(this.CurrentPage);
    }

Sign In or Register to comment.