RelativeLayout: Priority in constraints?

GyllionGyllion NLMember ✭✭

Hello everyone,

I was wondering if there is anything available in Xamarin.Forms to execute constraints in a custom priority. Why would you want that? Imagine an element that is dependent on its own property (for example Width or Height). Here is an example to center boxviewB in front of another boxviewA:

relativeLayout.Children.Add(boxViewB, widthConstraint: Constraint.RelativeToView(boxViewA, (parent, sibling) => sibling.Width * 0.5),
                                      heightConstraint: Constraint.RelativeToView(boxViewA, (parent, sibling) => sibling.Height * 0.5),
                                      xConstraint: Constraint.RelativeToView(boxViewA, (parent, sibling) => sibling.X + (sibling.Width * 0.5) - (boxViewB.Width * 0.5)),
                                      yConstraint: Constraint.RelativeToView(boxViewA, (parent, sibling) => sibling.Y + (sibling.Height * 0.5) - (boxviewB.Height * 0.5)));

This will not work, since xConstraint will always be called first. Why would you not want to add boxViewB first and make it dependent on boxViewA? Because maybe boxViewA could be an element which has a bindable width and height.

Sign In or Register to comment.