I have a TableView
with few sections. In my TableSection
I want to display different controls depending on the platform. I want to use the usual TextCell
for iOS and a custom ViewCell
for Android. I have tried the following code:
<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>
The above code does not work. It gives me an error: Object reference not set to an instance of an object
.
Am I missing something? Should I be using a different x:TypeArguments
?
Edit:
Edited to incorporate @Fahadsk answer and now getting the error: System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
Anyone knows why I'm getting this?
OnPlatform is obsolete as of version 2.3.4.
Use following syntax in your code
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android" Value="0, 0, 0, 0"/>
<On Platform="iOS" Value="0, 20, 0, 0"/>
</OnPlatform>
For more info on this and this pull request, also check out this blog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With