在CollectionView DataTemplate中的标签高度

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

Label height in a CollectionView DataTemplate

问题

Objects 在 CollectionView 或 DataTemplate 中是否会自动填充或其他什么?我可以尝试更改 CollectionView 中标签的高度,但这只会影响标签部分,而不是我想要减小的额外填充。当我减小标签高度时,它只是遮挡了文本,所以我想知道是否有一种方法可以减小这个填充或边距,因为在 PC 上看起来不太好。

我有的基本 XAML 代码如下:

<CollectionView
    x:Name="ResponseCollectionView"
    ItemsSource="{Binding Responses}"
    BackgroundColor="#404040"
    HeightRequest="200"
>
    <CollectionView.ItemTemplate>
        <DataTemplate x:DataType="{x:Type x:String}">
            <Label Text="{Binding .}" BackgroundColor="#303030" />
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

并且看起来像这样:
在CollectionView DataTemplate中的标签高度

英文:

Are the objects in the CollectionView or DataTemplate automatically padded or something? I can try to change the height of the label in a CollectionView but that only affects the label portion of it and not this extra padding which I would like to reduce. When I reduce label height, it just masks the text so I'm wondering if there is a way to reduce this padding or margin because it doesn't look great on PC.

The basic xaml code I have is this:

            &lt;CollectionView
            x:Name=&quot;ResponseCollectionView&quot;
            ItemsSource=&quot;{Binding Responses}&quot;
            BackgroundColor=&quot;#404040&quot;
            HeightRequest=&quot;200&quot; 
            &gt;

            &lt;CollectionView.ItemTemplate&gt;
                &lt;DataTemplate x:DataType=&quot;{x:Type x:String}&quot; &gt;
                    &lt;Label Text=&quot;{Binding .}&quot; BackgroundColor=&quot;#303030&quot; /&gt;
                &lt;/DataTemplate&gt;
            &lt;/CollectionView.ItemTemplate&gt;
        &lt;/CollectionView&gt;

And it looks like this:
在CollectionView DataTemplate中的标签高度

答案1

得分: 1

The padding issue is caused by the Windows implementation of CollectionView having an inaccessible Checkbox included in each line. The perceived padding is caused by the height of the line not reducing to smaller than the height of the checkbox. If you go in-depth into the live layout for the CollectionView you can see the checkbox and how it affects the height.

英文:

The padding issue is caused by the Windows implementation of CollectionView having an inaccessible Checkbox included in each line. The perceived padding is caused by the height of the line not reducing to smaller than the height of the checkbox. If you go in-depth into the live layout for the CollectionView you can see the checkbox and how it affects the height.

huangapple
  • 本文由 发表于 2023年5月14日 23:15:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248220.html
匿名

发表评论

匿名网友

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

确定