英文:
How can I remove the space between the GroupHeaderTemplate and the ItemTemplate in a CollectionView on Windows .NET MAUI
问题
Here's the translated content:
"在没有得到答案的情况下,我重新提出我想要解决的问题。我正在.NET MAUI中开发一个联系人列表。然而,我的GroupHeaderTemplate周围有填充。这个问题只发生在Windows上。正如你所看到的,我在Android上没有这个问题。
以下是在Android和Windows上的结果。
<CollectionView Grid.Row="2"
ItemsSource="{Binding Contacts}"
SelectionMode="None"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
VerticalScrollBarVisibility="Always"
IsGrouped="True">
<!-- 群组头部 -->
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<Label Text="{Binding Name}"
FontSize="12" HeightRequest="20"
FontFamily="{x:Static constants:FontFamilies.TEXT_BOLD}"
BackgroundColor="{StaticResource HeaderGrey}"
Padding="20,0,0,4" VerticalTextAlignment="Center"
HorizontalOptions="FillAndExpand"/>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:Contact">
<VerticalStackLayout>
<Label HeightRequest="39"
VerticalTextAlignment="Center"
Padding="20,0,0,0">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding Firstname}"/>
<Span Text=" "/>
<Span Text="{Binding Name}"
FontFamily="{x:Static constants:FontFamilies.TEXT_BOLD}"/>
</FormattedString>
</Label.FormattedText>
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="ContactSelected"
Command="{Binding Source=
{RelativeSource AncestorType={x:Type local:ContactViewModel}},
Path=DisplayContactCommand}"
CommandParameter="{Binding Id}"/>
</Label.GestureRecognizers>
</Label>
<BoxView HeightRequest="1" BackgroundColor="{StaticResource SeparatorCellGrey}"/>
</VerticalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
我尝试了一切。也许有一个需要修改以适应Windows平台的处理程序,但我找不到它。希望能解决这个困扰我很长时间的问题。"
英文:
Having not had an answer to my question, I am relaunching the subject for which I would like to have the solution. I am developing a contact list in .NET MAUI. However I have padding that goes around my GroupHeaderTemplate. This issue only occurs on Windows. As you can see I don't have this problem on Android.
Here is the result on Android and Windows.
<CollectionView Grid.Row="2"
ItemsSource="{Binding Contacts}"
SelectionMode="None"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
VerticalScrollBarVisibility="Always"
IsGrouped="True">
<!-- En-tête de groupe -->
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<Label Text="{Binding Name}"
FontSize="12" HeightRequest="20"
FontFamily="{x:Static constants:FontFamilies.TEXT_BOLD}"
BackgroundColor="{StaticResource HeaderGrey}"
Padding="20,0,0,4" VerticalTextAlignment="Center"
HorizontalOptions="FillAndExpand"/>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:Contact">
<VerticalStackLayout>
<Label HeightRequest="39"
VerticalTextAlignment="Center"
Padding="20,0,0,0">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding Firstname}"/>
<Span Text=" "/>
<Span Text="{Binding Name}"
FontFamily="{x:Static constants:FontFamilies.TEXT_BOLD}"/>
</FormattedString>
</Label.FormattedText>
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="ContactSelected"
Command="{Binding Source=
{RelativeSource AncestorType={x:Type local:ContactViewModel}},
Path=DisplayContactCommand}"
CommandParameter="{Binding Id}"/>
</Label.GestureRecognizers>
</Label>
<BoxView HeightRequest="1" BackgroundColor="{StaticResource SeparatorCellGrey}"/>
</VerticalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
I have tried everything. Maybe there is a handler to modify for Windows platform but I can't find it. Hoping to have a solution for this problem that I have had for a long time.
答案1
得分: 1
是的,就像您所说的那样。
我在我的一侧进行了测试。结果是,在Windows上,默认情况下有一个最小高度,即使我们将Label的高度设置得非常小,CollectionView.GroupHeaderTemplate
仍然占据默认的最小高度。我们可以增加GroupHeader
的高度,但在尝试减小GroupHeader
的高度后,我们发现其高度在达到最小高度后不能再变小。
正如您所说,在Android上一切正常。
关于Windows上的这个问题,您可以在这里创建一个新的问题。
非常感谢您对maui的支持和反馈。
最好的问候!
杰西
英文:
Yes, it is just the case as you said.
I did a test on my side. The result is that on windows, there is a minimum height by default, even if we set the Label height very small, CollectionView.GroupHeaderTemplate
still occupies the default minimum height. We can increase the height of the GroupHeader
, but after trying to reduce the height of the GroupHeader
, we find that its height cannot be smaller after reaching the minimum height.
And as you said, on Android, everything works fine.
For this problem on windows, you can create a new issue here.
Thanks very much for your support for maui and feedback.
Best regards!
Jessie
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论