Mau*_*nas 4 c# xaml xamarin.ios xamarin.android xamarin.forms
我正在尝试根据其运行的设备更改条目的背景。我尝试根据以下信息进行操作:https : //developer.xamarin.com/guides/xamarin-forms/xaml/passing-arguments/
并得到了这个:
<Entry TextColor="White"
x:Name="entryTop"
HeightRequest="40"
WidthRequest="150"
RelativeLayout.XConstraint = "{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=.48,
Constant=10}"
RelativeLayout.YConstraint = "{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=0,
Constant=5}" >
<Entry.BackgroundColor>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="Transparent" />
<On Platform="iOS" Value="white" />
</OnPlatform>
</Entry.BackgroundColor>
</Entry>
Run Code Online (Sandbox Code Playgroud)
当我尝试构建我的项目时,我收到此错误:没有为 找到属性、可绑定属性或事件BackgroundColor,或者值和属性之间的类型不匹配。
我尝试了颜色工厂方法和几个TypeArguments,但似乎无法得到正确的方法。
我找到了答案:
<Entry.BackgroundColor>
<OnPlatform x:TypeArguments="Color"
Android="#5b5b5b"
iOS="#fff">
</OnPlatform>
</Entry.BackgroundColor>
Run Code Online (Sandbox Code Playgroud)
以这种方式使用时,TypeArgument Color 仅接收十六进制值。它不适用于 RGB 或静态颜色(“白色”、“黑色”等)。我希望这有帮助。
| 归档时间: |
|
| 查看次数: |
2737 次 |
| 最近记录: |