question

6666666 avatar image
0 Votes"
6666666 asked CherryBu-MSFT commented

The OnAppearing will not call when first open?

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?

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

CherryBu-MSFT avatar image
0 Votes"
CherryBu-MSFT answered CherryBu-MSFT commented

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.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I need the second page 's OnAppearing will be called how to fix it?

as you say even both of the pages are content page I tap the second page the OnAppearing will nog be called too.

0 Votes 0 ·

Hi @65841535 You can use my second code, when you tap the second page, the current page OnAppearing will be called.

0 Votes 0 ·

Thank you @CherryBu-MSFT what is the different between content page and navigationpage

0 Votes 0 ·
Show more comments