可以在GroupHeaderTemplate中绑定TextColor属性标签吗?
这是我的源代码:
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell Height="25">
<StackLayout VerticalOptions="FillAndExpand" Padding="5"
BackgroundColor="#0477B3">
<Label Text="{Binding Key, Converter={StaticResource dateConverter}}"
TextColor="#ffffff" VerticalOptions="Center"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
BR 最大
答案 0 :(得分:0)
组的BindingContext是分组本身。在不了解您的代码的情况下,这里是一个如何绑定到组头模板中的分组对象的示例:
<ListView ItemsSource="{Binding}"
IsGroupingEnabled="true" GroupDisplayBinding="{ Binding Name }"
GroupShortNameBinding ="{ Binding ShortName }">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell Height="25">
<StackLayout VerticalOptions="FillAndExpand" Padding="5"
BackgroundColor="#0477B3">
<!-- Name refers to Group.Name, depeding on your data you can use the key of your grouping here -->
<Label Text="{Binding Name}" VerticalOptions="Center"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{ Binding Title }" Detail="{ Binding Description }" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
代码:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
ObservableCollection<Group> groupedItems = new ObservableCollection<Group>();
Group group = new Group("First Group");
groupedItems.Add(group);
Item item = new Item("First Item", "First Item Description");
group.Add(item);
this.BindingContext = groupedItems;
}
}
public class Item
{
public String Title { get; private set; }
public String Description { get; private set; }
public Item(String title, String description)
{
Title = title;
Description = description;
}
}
public class Group : ObservableCollection<Item>
{
public String Name { get; private set; }
public Group(String Name)
{
this.Name = Name;
}
}
从here
获取和修改的示例