XAML 如何删除Windows .NET MAUI上集合视图中GroupHeaderTemplate和ItemTemplate之间的空格

ngynwnxp  于 2023-04-18  发布在  Windows
关注(0)|答案(1)|浏览(124)

没有回答我的问题,我重新启动的主题,我想有解决方案.我正在开发一个联系人列表.NET MAUI.然而,我有填充,围绕我的GroupHeaderTemplate.这个问题只发生在Windows.正如你所看到的,我没有这个问题在Android上.
这是Android和Windows上的结果。
Android:

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>

我已经尝试了一切.也许有一个处理程序修改为Windows平台,但我找不到它.希望有一个解决这个问题,我有很长一段时间.

wpcxdonn

wpcxdonn1#

是的,正如你所说的那样。
我这边做了一个测试,结果是在windows上,默认有一个最小高度,即使我们把Label高度设置得很小,CollectionView.GroupHeaderTemplate仍然占据默认的最小高度,我们可以增加GroupHeader的高度,但是尝试降低GroupHeader的高度后,发现达到最小高度后,它的高度不能再小了。
就像你说的,在Android上,一切都很好。
对于Windows上的此问题,您可以创建新问题here
非常感谢您对maui的支持和反馈。
最好的问候!
杰西

相关问题