英文:
.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:
- Create a .NET MAUI App
- replace the XAML code in MainPage, the CollectionView has LightBlue background
- run on Android emulator
- 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:
- Create a .NET MAUI App
- replace the XAML code in MainPage, the CollectionView has LightBlue background
- run on Android emulator
- 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">
<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>
</ContentPage>
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论