I have a TabbedPage with two child pages PageA and PageB (in the same order). On starting the tabbed page, PageA's OnAppearing method is called twice. How do I prevent this from happeinng?
Here's the sample code for the TabbedPage:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:SampleApp.Pages"
x:Class="SampleApp.TabbedPage1">
<views:PageA Title="Page A" />
<views:PageB Title="Page B" />
</TabbedPage>
Ok, I found the solution. Since PageA in the example is the first page, as soon as InitializeComponent of the main page is called, the page with 0 index is initialized. Also, it appears that Xamarin.Forms sets the CurrentPage property to the first page in the child list resulting in OnAppearing method being called twice. To prevent this from happening, you can set the CurrentPage property of the TabbedPage to null.
Here's the example:
public TabbedPage1()
{
InitializeComponent();
CurrentPage = null;
}