gpt4 book ai didi

xaml - Xamarin.Forms:如何正确使用来选择要在TableSection中使用的控件?

转载 作者:行者123 更新时间:2023-12-04 08:31:55 24 4
gpt4 key购买 nike

我有几节的TableView。在我的TableSection中,我想根据平台显示不同的控件。我想为iOS使用常规的TextCell,为Android使用自定义的ViewCell。我尝试了以下代码:

<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>

上面的代码不起作用。它给我一个错误: 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 is obsolete as of version 2.3.4.



在代码中使用以下语法
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android" Value="0, 0, 0, 0"/>
<On Platform="iOS" Value="0, 20, 0, 0"/>
</OnPlatform>

有关 this和此 pull request的更多信息,也请查看此 blog

关于xaml - Xamarin.Forms:如何正确使用<OnPlatform>来选择要在TableSection中使用的控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48741131/

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