.NET MAUI中的CollectionView在iPhone/iPad上未正确显示。

huangapple go评论71阅读模式
英文:

.NET MAUI CollectionView inside a Grid not shown correct on iPhone/iPad

问题

以下是您要翻译的内容:

"The MainPage of a simple .Net MAUI App contains a Grid with 4 Rows, all with the same height (*). They contain: Label, CollectionView, Button, Label
On Windows and Android the page is shown correct.
But on iPhone/iPad the CollectionView is much too high. It covers the Button and Label below (or it pushes them outside the screen)

When using a fix value for Grid.Row=1 the issue does not happen

Visual Studio 2022, Version 17.6.1
.Net 7.0

Reproduce:

  1. Create a .NET MAUI App
  2. replace the XAML code in MainPage, the CollectionView has LightBlue background
  3. run on Android emulator
  4. run on iOS simulator

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

"

英文:

The MainPage of a simple .Net MAUI App contains a Grid with 4 Rows, all with the same height (*). They contain: Label, CollectionView, Button, Label
On Windows and Android the page is shown correct.
But on iPhone/iPad the CollectionView is much too high. It covers the Button and Label below (or it pushes them outside the screen)

When using a fix value for Grid.Row=1 the issue does not happen

Visual Studio 2022, Version 17.6.1
.Net 7.0

Reproduce:

  1. Create a .NET MAUI App
  2. replace the XAML code in MainPage, the CollectionView has LightBlue background
  3. run on Android emulator
  4. run on iOS simulator

<ContentPage x:Class="MauiApp3.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

&lt;Grid BackgroundColor=&quot;LightGray&quot; RowDefinitions=&quot;*,*,*,*&quot;&gt;
    &lt;Label Margin=&quot;10&quot; FontSize=&quot;30&quot; Text=&quot;Header&quot; /&gt;
    &lt;CollectionView Grid.Row=&quot;1&quot; Margin=&quot;10&quot; BackgroundColor=&quot;LightBlue&quot;&gt;

    &lt;/CollectionView&gt;
    &lt;Button
        Grid.Row=&quot;2&quot; Margin=&quot;10&quot; BackgroundColor=&quot;Grey&quot;
        FontSize=&quot;40&quot; Text=&quot;Button&quot; /&gt;
    &lt;Label
        Grid.Row=&quot;3&quot; Margin=&quot;10&quot; BackgroundColor=&quot;Coral&quot;
        FontSize=&quot;40&quot; Text=&quot;Footer&quot; /&gt;
&lt;/Grid&gt;

</ContentPage>

.NET MAUI中的CollectionView在iPhone/iPad上未正确显示。

答案1

得分: 1

这是一个已在GitHub上报告的已知问题 - 使iOS上的CollectionView测量内容大小 #14951[iOS] 应用程序在iOS上与ScrollView、StackLayout、Editor和CollectionView的组合上卡住 #14955,请在GitHub上关注进展。

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

您还可以尝试使用.NET Upgrade Assistant升级到.NET 8,作为另一种临时解决方案。有关更多信息,您可以参考宣布支持.NET MAUI的.NET Upgrade Assistant的新版本

英文:

This is a known issue reported at GitHub - Make CollectionView on iOS measure to content size #14951 and [iOS] Application stucks on iOS with combination of ScrollView, StackLayout, Editor and CollectionView #14955, please follow the progress at GitHub.

As descripted in the first merged thread, to fix the issue, PG team need modify the CollectionView on iOS to use its ContentSize as the value for GetDesiredSize; this forces the CollectionView to size to its content rather than attempting to fill the whole screen. So we may need for the next release of .net to get it fixed.

You can also try to use the .NET Upgrade Assistant to upgrade to .NET 8 as an alternative workaround. For more information, you can refer to Announcing a new version of the .NET Upgrade Assistant with support for .NET MAUI.

huangapple
  • 本文由 发表于 2023年5月25日 18:39:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331387.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定