Reputation: 91
I have this list view but i dont know how to set style for the section titles. How can it be done in Xamarin? Have not found anything for that
<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>
Upvotes: 2
Views: 558
Reputation: 6098
You will want to use a ListView.GroupHeaderTemplate
with a ViewCell
in the DataTemplate
. E.g:
<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>
Now you can just style the Label however you want.
Upvotes: 4