网格内的 .NET MAUI CollectionView 在 iPhone/iPad 上未正确显示

标签 .net iphone ipad maui collectionview

一个简单的 .Net MAUI 应用程序的主页包含一个具有 4 行的网格,所有行具有相同的高度 (*)。它们包含:Label、CollectionView、Button、Label 在 Windows 和 Android 上,页面显示正确。 但在 iPhone/iPad 上,CollectionView 太高了。它覆盖了下面的按钮和标签(或者将它们推到屏幕之外)

使用 Grid.Row=1 的固定值时,不会出现此问题

Visual Studio 2022,版本 17.6.1 .Net 7.0

重现:

  1. 创建 .NET MAUI 应用
  2. 替换MainPage中的XAML代码,CollectionView具有浅蓝色背景
  3. 在 Android 模拟器上运行
  4. 在 iOS 模拟器上运行
<Grid BackgroundColor="LightGray" RowDefinitions="*,*,*,*">
    <Label Margin="10" FontSize="30" Text="Header" />
    <CollectionView Grid.Row="1" Margin="10" BackgroundColor="LightBlue">

    </CollectionView>
    <Button
        Grid.Row="2" Margin="10" BackgroundColor="Grey"
        FontSize="40" Text="Button" />
    <Label
        Grid.Row="3" Margin="10" BackgroundColor="Coral"
        FontSize="40" Text="Footer" />
</Grid>

Android vs iPhone

最佳答案

这是 GitHub 上报告的已知问题 - Make CollectionView on iOS measure to content size #14951[iOS] Application stucks on iOS with combination of ScrollView, StackLayout, Editor and CollectionView #14955 ,请关注GitHub上的进展。

如第一个合并线程中所述,为了解决该问题,PG 团队需要修改 iOS 上的 CollectionView 以将其 ContentSize 用作GetDesiredSize 的值;这会强制 CollectionView 根据其内容调整大小,而不是尝试填充整个屏幕。因此,我们可能需要下一个版本的 .net 来修复它。

您还可以尝试使用the .NET Upgrade Assistant升级到 .NET 8 作为替代解决方法。更多信息,您可以引用Announcing a new version of the .NET Upgrade Assistant with support for .NET MAUI .

关于网格内的 .NET MAUI CollectionView 在 iPhone/iPad 上未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76331387/

相关文章:

c# - 异步方法在 ASP.NET (MVC) 中的何处执行?

c# - Visual Studio 2012 代码分析错误 CA0058

.net - 如何开始使用单声道分析器 2.8?

iphone - 在 UITableView 上显示徽章信息

ipad - 在 ipad html5 站点中使用键盘自动对焦

c# - 我正忙于编写 C# IBM MQ 客户端应用程序,并不断收到 "Exception: The type initializer for ' IBM.WMQ.Nmqi.UnmanagedNmqiMQ' 抛出异常。”

iphone - 如何在自定义 View 中检测内部修饰?

javascript - 如何通过 javascript 检测 iPhone *4* 用户

iphone - 如何查看 iPhone 应用程序的启动时间?

ios - iOS 中每天在后台运行一个函数