listview - 如何更改 Xamarin 中的章节标题字体样式?

标签 listview xamarin xamarin.forms

我有这个 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.GroupHeaderTemplateViewCell。例如:

<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/

相关文章:

c# - 无法从 xamarin 中的 TableView RowSelected 加载 ViewController

c# - Xamarin.Forms 的 ECDsa

c# - 当前上下文中不存在名称 'Console' 在 xamarin 表单应用程序中

android - RelativeLayout 的行为与 ListView 项不同

Android - 如何获取应用程序的图标?

android - 缩放 ImageView 以适应屏幕宽度/高度,同时保持纵横比

xaml - Xamarin 标题栏文本居中(跨平台)

c# - 如何从堆栈导航 Xamarin Forms 中删除当前页面

c# - 在我的 C# XAML Windows 8.1 应用程序中,如何迭代我的 ListView?

java - 在 Android 中选择列表项时使列表项在屏幕上居中?