The OnAppearing will not call when first open?

打玻璃 1,546 Reputation points
2021-04-29T03:00:35.19+00:00

I created a simple xamarin.forms non-shell template

MainPage = new NavigationPage(new MainPage());

and the MainPage set to tabbed page

there are 2 pages in the tabbed page

if I close and re-open the APP the two page's OnAppearing will be called but If I tap the second page it will not be called.

and If I use PushAsync to open a page in the OnAppearing then I close it the two page's OnAppearing will not be called too.

why?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,825 questions
No comments
{count} votes

Accepted answer
  1. CherryBu-MSFT 326 Reputation points
    2021-04-29T06:28:04.757+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    if I close and re-open the APP the two page's OnAppearing will be called but If I tap the second page it will not be called.

    From Xamarin.Forms TabbedPage, populate the TabbedPage with a collection of child Page objects, such as a collection of ContentPage objects.

    If I use NavigationPage and ContentPage for second Page, I can encounter your probelm.

    <TabbedPage  
        x:Class="FormsSample.tabbedpage.TabbedPage4"  
        xmlns="http://xamarin.com/schemas/2014/forms"  
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
        xmlns:list="clr-namespace:FormsSample.collectionviewsample">  
        <!--  Pages can be added as references or inline  -->  
        <list:Page1 />  
        <!--<list:Page2 />-->  
        <NavigationPage>  
            <x:Arguments>  
                <list:Page2 />  
            </x:Arguments>  
        </NavigationPage>  
    </TabbedPage>  
    

    If I don't use NavigationPage and ContentPage, only first page's OnAppearing will be called when I open app, If I tap the second page, second page's OnAppearing will be called.

    <TabbedPage  
        x:Class="FormsSample.tabbedpage.TabbedPage4"  
        xmlns="http://xamarin.com/schemas/2014/forms"  
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
        xmlns:list="clr-namespace:FormsSample.collectionviewsample">  
        <!--  Pages can be added as references or inline  -->  
        <list:Page1 />  
        <list:Page2 />  
          
    </TabbedPage>  
    

    Best Regards,
    Cherry Bu
    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful