iam*_*hia 8 xaml xamarin xamarin.forms
我有TableView几个部分.在我TableSection我想根据平台显示不同的控件.我想使用通常TextCell的iOS和ViewCellAndroid 的自定义.我试过以下代码:
<TableSection Title="Activity">
<OnPlatform x:TypeArguments="View">
<On Platform="iOS">
<TextCell x:Name="btnCountIOS" Text="Count" Height="50" />
<TextCell x:Name="cardHistory" Text="History" StyleId="disclosure" Tapped="openHistoryPage" Height="50"/>
</On>
<On Platform="Android">
<local:MyViewCell NoTap="true" Height="50">
<Grid VerticalOptions="CenterAndExpand" Padding="20, 0">
<Label Style="{DynamicResource ListItemTextStyle}" HorizontalOptions="StartAndExpand" VerticalOptions="Center" Text="Today" />
<Label Style="{DynamicResource ListItemTextStyle}" TextColor="Gray" HorizontalOptions="End" x:Name="btnCountDroid" />
</Grid>
</local:MyViewCell>
<local:MyViewCell>
<!-- more code here -->
</local:MyViewCell>
</On>
</OnPlatform>
</TableSection>
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用.它给了我一个错误:Object reference not set to an instance of an object.
我错过了什么吗?我应该使用不同的x:TypeArguments吗?
编辑:
编辑纳入@Fahadsk答案,现在得到错误:System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.任何人都知道为什么我得到这个?
OnPlatform 自 2.3.4 版起已过时。
在您的代码中使用以下语法
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android" Value="0, 0, 0, 0"/>
<On Platform="iOS" Value="0, 20, 0, 0"/>
</OnPlatform>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2826 次 |
| 最近记录: |