title: Xamarin.Forms protected OnAppearing method - how to change bool value?
body: <p>In one of my pages in Xamarin.Forms app I want to detect, when OnAppearing method is called first time.</p>
  
  <p>I try to do this by add bool value, which when page is initializing is set to true, but when OnAppearing is called, the value is set to false.</p>
  
  <p>How it looks in code:</p>
  
  <pre><code>public partial class ListPage : ContentPage
  {
  
      bool FirstLoad = true;
  
      public ListPage()
      { 
          InitializeComponent();
  
      }
  
      protected async override void OnAppearing()
      {
          base.OnAppearing();
  
          Debug.WriteLine("***** OnAppearing ListPage");
  
          if (FirstLoad)
          {
  
              //Do something
              Debug.WriteLine("***** FirstLoad = true ");
  
          }
          else
          {
              //Do something else
              Debug.WriteLine("***** FirstLoad = false ");
          }
  
          FirstLoad = false;
  
      }
  </code></pre>
  
  <p>But it's not working. Always, when I activate page it returns me bool value as true.</p>
  
  <pre><code>[0:] ***** OnAppearing ListPage
  [0:] ***** FirstLoad = true 
  [0:] ***** OnAppearing ListPage
  [0:] ***** FirstLoad = true 
  [0:] ***** OnAppearing ListPage
  [0:] ***** FirstLoad = true 
  [0:] ***** OnAppearing ListPage
  [0:] ***** FirstLoad = true
  </code></pre>
  
  <p>I think the issue is that, the OnAppearing method is protected, but is there any way to handle with this?</p>
  
  <p>@Diego, thank you for your commitment.</p>
  
  <p>MainPage is my MasterDetailPage.</p>
  
  <p>I've created a grid in Lables and Images which have TapGestureRecognizers handlers:</p>
  
  <pre><code>                &lt;Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" HorizontalOptions="Center" VerticalOptions="Center" Text="Menu" FontSize="Large" TextColor="White"/&gt;
              &lt;!--&lt;Frame BackgroundColor="Transparent" BorderColor="Black" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" /&gt;--&gt;
              &lt;Image Source="vehicles.png" Grid.Row="1" Grid.Column="0" HorizontalOptions="Center" WidthRequest="40" IsOpaque="True"&gt;
                  &lt;Image.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped="ImgVehiclesTapGestureRecognizer_Tapped"/&gt;
                  &lt;/Image.GestureRecognizers&gt;
              &lt;/Image&gt;
              &lt;Label x:Name="LblVehiclesPage" Grid.Row="1" Grid.Column="1" Text="Pojazdy" VerticalOptions="Center" FontSize="Medium" TextColor="White" BackgroundColor="Transparent"&gt;
                  &lt;Label.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped="LblVehiclesPageTapGestureRecognizer_Tapped"/&gt;
                  &lt;/Label.GestureRecognizers&gt;
              &lt;/Label&gt;
              &lt;Image Source="list.png" Grid.Row="2" Grid.Column="0" HorizontalOptions="Center" WidthRequest="45" IsOpaque="True"&gt;
                  &lt;Image.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped="ImgListTapGestureRecognizer_Tapped"/&gt;
                  &lt;/Image.GestureRecognizers&gt;
              &lt;/Image&gt;
              &lt;Label x:Name="LblListPage" Grid.Row="2" Grid.Column="1"  Text="Lista" VerticalOptions="Center" FontSize="Medium" TextColor="White" BackgroundColor="Transparent"&gt;
                  &lt;Label.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped="LblListPageTapGestureRecognizer_Tapped"/&gt;
                  &lt;/Label.GestureRecognizers&gt;
              &lt;/Label&gt;
              &lt;Image Source="scheduler.png" Grid.Row="3" Grid.Column="0" HorizontalOptions="Center" WidthRequest="50" IsOpaque="True"&gt;
                  &lt;Image.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped="ImgSchedulerTapGestureRecognizer_Tapped"/&gt;
                  &lt;/Image.GestureRecognizers&gt;
              &lt;/Image&gt;
              &lt;Label x:Name="LblSchedulerPage" Grid.Row="3" Grid.Column="1" Text="Kalendarz" VerticalOptions="Center" FontSize="Medium" TextColor="White" BackgroundColor="Transparent"&gt;
                  &lt;Label.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped="LblSchedulerPageTapGestureRecognizer_Tapped"/&gt;
                  &lt;/Label.GestureRecognizers&gt;
              &lt;/Label&gt;
              &lt;Image Source="gmaps.png" Grid.Row="4" Grid.Column="0" HorizontalOptions="Center" WidthRequest="40" IsOpaque="True"&gt;
                  &lt;Image.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped="ImgMapTapGestureRecognizer_Tapped"/&gt;
                  &lt;/Image.GestureRecognizers&gt;
              &lt;/Image&gt;
              &lt;Label x:Name="LblMapPage" Grid.Row="4" Grid.Column="1" Text="Mapa" VerticalOptions="Center" FontSize="Medium" TextColor="White" BackgroundColor="Transparent"&gt;
                  &lt;Label.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer
                          Tapped="LblMapPageTapGestureRecognizer_Tapped"/&gt;
                  &lt;/Label.GestureRecognizers&gt;
              &lt;/Label&gt;
          &lt;/Grid&gt;
  </code></pre>
  
  <p>(I don't want to use ListView, because performance will be worse at the startup).</p>
  
  <p>In MainPage ctor, I've intialized ListPage as Detail:</p>
  
  <pre><code>Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(ListPage)));
  </code></pre>
  
  <p>Also, use this code, in TapGestureRecognizers f.e - VehiclesPage:</p>
  
  <pre><code>        private void LblVehiclesPageTapGestureRecognizer_Tapped(object sender, EventArgs e)
      {
          //Detail = new NavigationPage(new VehiclesPage());
  
          Detail = ((Page)Activator.CreateInstance(typeof(VehiclesPage)));
          IsPresented = false;
      }
  </code></pre>
  
  <p>I expect, that all of my pages will upload on startup. And, when I navigate to this page via MasterPage it will be in memory, and then I can properly use OnAppearing method.</p>
  
  <p>Also, I've tried to initialize pages from class, f.e</p>
  
  <pre><code>    public class MasterPageItem
      {
           public string Title { get; set; }
           public string Icon { get; set; }
           public Type TargetType { get; set; }
      }
  </code></pre>
  
  <p>But, don't know how can I properly use this.</p>