XAML .NET MAUI更改文本单元格中的字体大小

eoigrqb6  于 12个月前  发布在  .NET
关注(0)|答案(1)|浏览(167)

所以我最近开始了我的第一个项目与.net毛伊岛和一切都看起来很好,直到我尝试造型我的应用程序,使它看起来更好。我有一个非常简单的ListView,它绑定了一个人员列表。在列表视图中有一个文本单元格,它绑定到人名。现在我试图改变文本单元格中文本的字体大小,但我不知道如何改变,因为没有fontsize属性。
这是我的代码:

<ListView x:Name="Persons"
        Grid.Column="0"
        Grid.Row="1"
        ItemSelected="Persons_ItemSelected" 
        Margin="10,10,10,0"
        RowHeight="40"
        BackgroundColor="LightGray"
        >
        <ListView.ItemTemplate>
            <DataTemplate>
                <TextCell Text="{Binding Name}"></TextCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

我试着用谷歌搜索这个问题,但没有任何结果。

kjthegm6

kjthegm61#

从文档TextCell Class中,我们可以发现TextCell不具有FontSize属性。
但是你可以使用Label来实现这一点,它具有FontSize属性。
请参考以下代码:

<ListView ItemsSource="{Binding Items}" HasUnevenRows="True"> 
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                     <!-- use Label instead  -->
                    <Label  Text="{Binding Name}" FontSize="Caption"/>
                </ViewCell>

            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

相关问题