gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 20:54:30 28 4
gpt4 key购买 nike

我想将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>

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

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

最佳答案

您正在将约束应用于 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>

此外,第一个 ConstraintExpression 标记上缺少右大括号 (})。

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

关于xamarin - 如何在 XAML 中制作特定于平台的relativelayout.xconstraint?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40889142/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com