我正在研究RelativeLayout
。我想分别为iOS和Anroid为ConstraintExpression
提供X,Y, Width and Height
。
如何针对以下代码做到这一点
<Picker ItemsSource="{Binding AttendanceType }"
TitleColor="Black" Title="--Select--"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=.9}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=.05}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0,Constant=22}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=.28}">
</Picker>
答案 0 :(得分:2)
这应该使用xaml的“压缩” onplatform语法进行工作:
<Picker ItemsSource="{Binding AttendanceType }"
TitleColor="Black" Title="--Select--"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor={OnPlatform Android=.9, iOS=.8}}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor={OnPlatform Android=.05, iOS=.04}}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor={OnPlatform Android=0, iOS=1},Constant={OnPlatform Android=22, iOS=21}}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor={OnPlatform Android=.28, iOS=.27}}">
</Picker>
有关标记扩展的更多信息,请参见: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/markup-extensions/consuming#onplatform-markup-extension