Suchith
Suchith

Reputation: 1527

How can I make platform specific RelativeLayout.XConstraint in XAML?

I want to take RelativeLayout.XConstraint with some platform specific value. And also i want to do this in xaml with OnPlatform keyword. I tried this one without luck,

<RelativeLayout>
    <RelativeLayout.XConstraint>
         <OnPlatform x:TypeArguments="Constraint" Android="{ConstraintExpression Type=Constant,Constant=6" iOS="{ConstraintExpression Type=Constant,Constant=3}" />
     </RelativeLayout.XConstraint>
</RelativeLayout>

And also tried this one https://forums.xamarin.com/discussion/57281/how-can-i-make-platform-specific-relativelayout-xconstraint-in-xaml but it is showing exception "Constraints as specified contain an unsolvable loop".

Here what would be the x:TypeArguments for RelativeLayout.XConstraint or any other approach? Looking forward to any hints/suggestion on this.

Upvotes: 2

Views: 1076

Answers (1)

Stephane Delcroix
Stephane Delcroix

Reputation: 16222

You are applying the constraint to the RelativeLayout itself, but constraint are meant to be applied on items of the layout, like this.

<RelativeLayout>
  <Label Text="Foo">
    <RelativeLayout.XConstraint>
      <OnPlatform x:TypeArguments="Constraint" Android="{ConstraintExpression Type=Constant,Constant=6}" iOS="{ConstraintExpression Type=Constant,Constant=3}" />
    </RelativeLayout.XConstraint>
  </Label>
</RelativeLayout>

Also, you're missing a closing curly brace (}) on the first ConstraintExpression markup.

I tested this, it works just fine with XamlC turned off. If you are running XF 2.3.3, you might be hitting https://bugzilla.xamarin.com/show_bug.cgi?id=48242, but a fix exists (https://github.com/xamarin/Xamarin.Forms/pull/580) and will be released as part of the coming service release.

Upvotes: 5

Related Questions