title: Xamarin.Forms: Change RelativeLayout constraints afterwards
body: <p>Is it possible to change the constraints of a <a href="https://developer.xamarin.com/api/type/Xamarin.Forms.RelativeLayout/" rel="noreferrer"><code>RelativeLayout</code></a> after they have been set one time?</p>
  
  <p>In the documentation I see methods like <code>GetBoundsConstraint(BindableObject)</code>, but I think you can only use them if you have a XAML file. For now I'm trying to do this in code. I get <code>null</code> if I try</p>
  
  <pre><code>RelativeLayout.GetBoundsConstraint(this.label);
  </code></pre>
  
  <p>The only way I found out is to remove the children from the layout and add it with the new constraints again.</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>public class TestPage : ContentPage
  {
      private RelativeLayout relativeLayout;
      private BoxView view;
      private bool moreWidth = false;
  
      public TestPage()
      {
          this.view = new BoxView
          {
              BackgroundColor = Color.Yellow,
          };
  
          Button button = new Button
          {
              Text = "change",
              TextColor = Color.Black,
          };
  
          button.Clicked += Button_Clicked;
  
          this.relativeLayout = new RelativeLayout();
  
          this.relativeLayout.Children.Add(this.view,
              Constraint.Constant(0),
              Constraint.Constant(0),
              Constraint.Constant(80),
              Constraint.RelativeToParent((parent) =&gt;
              {
                  return parent.Height;
              }));
  
          this.relativeLayout.Children.Add(button,
              Constraint.RelativeToParent((parent) =&gt;
              {
                  return parent.Width / 2;
              }),
              Constraint.RelativeToParent((parent) =&gt;
              {
                  return parent.Height / 2;
              }));
  
          this.Content = this.relativeLayout;
      }
  
      private void Button_Clicked(object sender, EventArgs e)
      {
          double width = 0;
          if(this.moreWidth)
          {
              width = 120;
          }
          else
          {
              width = 80;
          }
          var c= BoundsConstraint.FromExpression((Expression&lt;Func&lt;Rectangle&gt;&gt;)(() =&gt; new Rectangle(0, 0, width, this.Content.Height)), new View[0]);
          RelativeLayout.SetBoundsConstraint(this.view, c);
          this.relativeLayout.ForceLayout();
          this.moreWidth = !this.moreWidth;
      }
  }
  </code></pre>