title: Add a Layout on Orientation change in Xamarin.Forms
body: <p>What I need to achieve is, Adding a Layout to the existing page on Changing the screen from Portrait to Landscape. I have managed to detect orientation change using <strong>void OnSizeAllocated(double width, double height)</strong> . But I cannot add a layout on this event.</p>
  
  <p><strong>My sample C# Code is</strong></p>
  
  <pre><code>   public class MyLayoutView : ContentPage
     {
        StackLayout portraitcontent = null;
        StackLayout landscapecontent = null;
        StackLayout footer = null;
  
     public MyLayoutView ()
      {
  
      portraitcontent = new StackLayout ();
      landscapecontent = new StackLayout ();
      footer = new StackLayout ();
  
      this.Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
      this.BackgroundColor = Color.FromHex ("#ffffff");
      this.Content = new StackLayout
          {
              Children =
              {
                  portraitcontent ,
                  landscapecontent ,
                  footer 
              }
              };
           }
     }
  </code></pre>
  
  <p><strong>OnSizeAllocated Method</strong></p>
  
  <pre><code>   protected override void OnSizeAllocated(double width, double height)
      {
          base.OnSizeAllocated(width, height);
  
          if (width &lt; height) {
              // In Portrait
              portraitcontent .IsVisible = true;
              landscapecontent.IsVisible = false;
              Debug.WriteLine ("Application Is in portrait");
          } else {
              // In Landscape
              portraitcontent .IsVisible = false;
              landscapecontent.IsVisible = true;
  
              landscapecontent.Children.Clear ();
  
              Label LandscapeLabel= new Label
              {
                Text = "&lt;Each Time Text Changes&gt;",
                HorizontalOptions = LayoutOptions.StartAndExpand,
                TextColor=Xamarin.Forms.Color.FromHex("#000000")
              };
  
              landscapecontent.Children.Add(LandscapeLabel); 
  
              Debug.WriteLine ("Application Is in Landscape");
          }
      }
  </code></pre>
  
  <p>It throws <strong>cannot modify the collection while reenterancy is blocked</strong> error. I need to add a new label in stacklayout each time when orientation changes. How can I achieve it in a proper way??</p>
  
  <p>Thanks in advance</p>