You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI中CollectionView/DataTemplate在Android与iOS表现差异求助

.NET MAUI CollectionView iOS端异常问题

我用.NET MAUI实现了一个带有DataTemplate的CollectionView,部署到Android和iOS设备时表现完全不同。之前在Xamarin中使用相同代码没有异常。添加WidthRequest(及边距)后Android端样式符合预期,但iOS端仍存在以下问题:

  • 打开应用时右侧内容不显示,应用疑似卡顿
  • 尝试滚动时,列表项随机缺失且界面完全卡死
    该功能在macOS(MacCatalyst)上运行正常。

相关XAML代码

<RefreshView x:DataType="local:ItemsViewModel" Command="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
        <CollectionView x:Name="ItemsListView" ItemsSource="{Binding Items}" SelectionMode="None">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid Padding="10" x:DataType="model:Cryptocurrency">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="auto" />
                        </Grid.ColumnDefinitions>

                        <Image Source="{Binding image}" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" HeightRequest="50" WidthRequest="50" Margin="0,0,10,0" />

                        <Label Text="{Binding name}" Grid.Row="0" Grid.Column="1"
                            LineBreakMode="NoWrap" 
                            Style="{DynamicResource ListItemTextStyle}" 
                            FontSize="16" />
                        <Label Text="Price" Grid.Row="0" Grid.Column="2"
                            LineBreakMode="NoWrap"  HorizontalTextAlignment="End" Padding="0,0,20,0"
                            Style="{DynamicResource ListItemTextStyle}" 
                            FontSize="16" />
                        <Label Text="x to ATH" Grid.Row="0" Grid.Column="3"
                            LineBreakMode="NoWrap" 
                            Style="{DynamicResource ListItemTextStyle}" 
                            FontSize="16" />

                        <Label Text="{Binding market_cap_rank}" Grid.Row="1" Grid.Column="1"
                            LineBreakMode="NoWrap"
                            Style="{DynamicResource ListItemDetailTextStyle}"
                            FontSize="13" />
                        <Label Text="{Binding current_price, StringFormat='{}{0:C}'}" Grid.Row="1" Grid.Column="2"
                            LineBreakMode="NoWrap" HorizontalTextAlignment="End" Padding="0,0,20,0"
                            Style="{DynamicResource ListItemDetailTextStyle}"
                            FontSize="13" />
                        <Label Text="{Binding RatioToATH}" Grid.Row="1" Grid.Column="3"
                            LineBreakMode="NoWrap"
                            Style="{DynamicResource ListItemDetailTextStyle}"
                            FontSize="13" />
                        
                        <Grid.GestureRecognizers>
                            <TapGestureRecognizer NumberOfTapsRequired="1" Command="{Binding Source={RelativeSource AncestorType={x:Type local:ItemsViewModel}}, Path=ItemTapped}"      
                                CommandParameter="{Binding .}">
                            </TapGestureRecognizer>
                        </Grid.GestureRecognizers>
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </RefreshView>

界面截图

界面截图1
界面截图2
界面截图3
MacCatalyst运行截图

内容的提问来源于stack exchange,提问作者René Winter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 11:35:22