Tabbed Page OnAppearing ()

I have a Tabbar Page Xamarin Form application that I am trying to customize. I transfer from the application only for all platforms. In iOS, there are a couple of functions that I used ViewDidDisappear (), ViewDidAppear () and ViewDidLoad ();

Today, the application loads the tabbed page as follows:

{
    Children.Add(new MyPage1());
    Children.Add(new MyPage2());
    Children.Add(new MyPage3());
    Children.Add(new MyPage4());
}

Each of the child pages is declared as follows: all inherit from ContentPage.

class MyPage1: ContentPage
{
        protected override void OnAppearing()
        {
            base.OnAppearing();
            Content = SomeContentPage;
        }
}

The problem I am facing is that OnAppearing () is called for all pages when only MyPage1 is displayed. I need to know when each child page loads.

I read about the message center, but I'm not sure how to implement it in this particular case. Would a message center be the best solution for this?

, , ?

+4
2

TabbedPage CurrentPage null .

0

- OnCurrentPageChanged TabbedPage.

protected override void OnCurrentPageChanged()
{
    base.OnCurrentPageChanged();

    if ( CurrentPage is YourContentPage page)
    {
        page.YourCustomCode();
    }
}
0

Source: https://habr.com/ru/post/1662188/


All Articles