如何在 XAML 中制作特定于平台的relativelayout.xconstraint?

Suc*_*ith 2 xamarin xamarin.forms

我想获取RelativeLayout.XConstraint一些平台特定的价值。我还想在 xaml 中使用 OnPlatform 关键字来执行此操作。我尝试过这个,但没有运气,

<RelativeLayout>
    <RelativeLayout.XConstraint>
         <OnPlatform x:TypeArguments="Constraint" Android="{ConstraintExpression Type=Constant,Constant=6" iOS="{ConstraintExpression Type=Constant,Constant=3}" />
     </RelativeLayout.XConstraint>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

还尝试了这个https://forums.xamarin.com/discussion/57281/how-can-i-make-platform-specific-relativelayout-xconstraint-in-xaml但它显示异常“指定的约束包含无法解决的环形”。

x:TypeArguments这里的forRelativeLayout.XConstraint或任何其他方法是什么?期待对此的任何提示/建议。

Ste*_*oix 5

您正在将约束应用于其RelativeLayout本身,但约束应该应用于布局的项目,如下所示。

<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>
Run Code Online (Sandbox Code Playgroud)

}另外,您在第一个标记上缺少右大括号 ( ) ConstraintExpression

我对此进行了测试,在 XamlC 关闭的情况下它工作得很好。如果您运行的是 XF 2.3.3,您可能会点击https://bugzilla.xamarin.com/show_bug.cgi?id=48242,但存在修复程序 ( https://github.com/xamarin/Xamarin.Forms/ pull/580)并将作为即将发布的服务版本的一部分发布。