我有这个 ListView ,但我不知道如何设置部分标题的样式。在 Xamarin 中如何实现?还没有找到任何东西
<ListView x:Name ="listView"
IsGroupingEnabled="true"
GroupDisplayBinding="{Binding sectionHeader}"
HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="10">
<StackLayout Orientation="Vertical">
<Label Text="{Binding Title1}" FontSize="12" FontAttributes="Bold"/>
<Label Text="{Binding Title2}" FontSize="12" FontAttributes="Bold"/>
<Label Text="{Binding SubTitle}" FontSize="12"/>
</StackLayout>
<Image Source="new_feedback_0.png" HorizontalOptions="EndAndExpand"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
最佳答案
您需要在DataTemplate
中使用ListView.GroupHeaderTemplate
和ViewCell
。例如:
<ListView x:Name ="listView"
IsGroupingEnabled="true"
<!--GroupDisplayBinding="{Binding sectionHeader}" Not Needed anymore since you are providing your own GroupHeaderTemplate for the group header view-->
HasUnevenRows="true">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding sectionHeader}" TextColor="Red" FontAttributes="Italic" />
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
...
</ListView.ItemTemplate>
</ListView>
现在您可以根据需要设置标签样式。
关于listview - 如何更改 Xamarin 中的章节标题字体样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41005144/