简体   繁体   中英

What happens in the OnAppearing of Xamarin Forms?

I have a Forms application which works good but I notice the background colors appear set incorrectly for a fraction of a second as the page appears.

I have this code for my OnAppearing

    protected override async void OnAppearing()
    {
        base.OnAppearing();
        Subscribe();
        vm.Theme = Settings.th.ToString();
        await SetCardButtons(Settings.cc.Text());
    }

Can someone explain what happens in the base.OnAppearing() and should this be the first or last line in my override?

what happens in the base.OnAppearing()

OnAppearing is a virtual method in the Page base class, that does not contain any code (but that does not mean it does not do anything).

Depending upon which Page subclass you are using, different things might be performed, like the MasterDetailPage performs logic to determine if it should be displayed as a splitview (side-by-side) mode, the native iOS code would do this on an iPad, ....

should this be the first or last line in my override?

Normally this would be called first in your override to allow any custom subclass code to setup the UI properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM