Advanced RelativeLayout Constraints in XAML

CarlesGarciaCarlesGarcia ESMember
edited August 2015 in Xamarin.Forms

Is it possible (IN XAML) to establish the position of an element depending on the position of a second object and the height of the Parent?

The conceptual formula would be this:

PrimaryObject.X = ( SecondaryObject.X, Factor=1 ) - ( PrimaryObject.Parent.Height, Factor=0.4 )

Posts

  • ylemsoulylemsoul RUMember ✭✭✭
    edited August 2015

    With Constraint.FromExpression(..) you can build any complex constraints in the code. But XAML's ConstraintExpressionExtension doesn't support expressions. One thing you can do is implementing custom markup extension which will follow your logic and will do Constraint.FromExpression(..) under the hood. It will be reliable.

    But if you want to use existing one I beleive there is no simple way. I came up with this solution (not sure if it is reliable):
    it uses 2 reference empty content views that will represent 2 summands:
    1) ( SecondaryObject.X, Factor=1 )
    2) - ( PrimaryObject.Parent.Height, Factor=0.4 )
    Then we utilize horizontal StackLayout. His Width will be expanded to the sum of 2 additional content views which will have Width bounded to 2 aforementioned content views:


    Not readable without comments. For this task I would not hesitate to use code-behind actually :smile:

  • A creative solution !!
    It works perfectly.
    Thank you very much for your help. :smile:

Sign In or Register to comment.