RelativeLayout code to XAML translation

ossentooossentoo GBMember ✭✭
edited December 2015 in Xamarin.Forms

Hi all,

I've got some sample c# code that I'm trying to translate into XAML because that's the standard we are using on our project. There's a piece of relativelayout code that I'm struggling to create a correct layout for. It's to get an image displayed in the middle of a contentpage:

            Constraint.RelativeToParent(parent => ((parent.Width / 2) - (face.Width / 2))),
            Constraint.RelativeToParent(parent => parent.Height * .25),
            Constraint.RelativeToParent(parent => parent.Width * .5),
            Constraint.RelativeToParent(parent => parent.Width * .5)

        face.SizeChanged += (sender, e) => {

So far I've translated this to:

`<RelativeLayout HorizontalOptions="CenterAndExpand" HeightRequest="100">
    <Image Source="profile1.png"
                RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5}"
                RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.25}"
                RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5}"
                RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5}">         

The bit that I'm unable to understand is how to base a constraint on the dimension on the parent and some other object simultaneously [ i.e. this expression ((parent.Width / 2) - (face.Width / 2))]

In XAML, there is only the RelativeToParent type of constraint.


Best Answer


Sign In or Register to comment.