ListView页眉和页脚没有出现

时间:2015-06-12 04:02:29

标签: c# android xamarin.forms

我在内容页面中有以下列表视图。数据绑定正常,但页眉和页脚从未出现过。

<?xml version="1.0" encoding="UTF-8" ?>

<ContentPage.Content>
        <SearchBar x:Name="SearchFor"
            Placeholder="search for"
            Text="{Binding Path=SearchText}"
            TextChanged="OnValueChanged" 
            SearchButtonPressed="OnSearch" />

        <ListView x:Name="listView" ItemSelected="OnItemSelected" ItemsSource="{Binding Item}"
Header="{Binding ItemID}"
Footer="{Binding SupplierItemDesc}">
<ListView.HeaderTemplate >
  <DataTemplate>
    <StackLayout Orientation="Horizontal" 
        Padding="10,5,5,10"
        BackgroundColor="Yellow">
      <Label Text="~~"/>
      <Label Text="{Binding .}"/>
      <Label Text="~~"/>
    </StackLayout>
  </DataTemplate>
</ListView.HeaderTemplate>
<ListView.ItemTemplate>
    <DataTemplate>
        <TextCell Text="{Binding RetailCurrencyCode}" Detail="{Binding RetailValue}"></TextCell>
    </DataTemplate>
</ListView.ItemTemplate>


</ContentPage.Content>

即使我启用了分组模板,它也不会显示任何内容。

2 个答案:

答案 0 :(得分:0)

将您的DataTemplate包装在ViewCell中并给它一个高度:

<ListView.HeaderTemplate >
    <DataTemplate>
            <StackLayout Orientation="Horizontal" 
                Padding="10,5,5,10"
                BackgroundColor="Yellow" HeightRequest="40">
                  <Label Text="~~"/>
                  <Label Text="{Binding .}"/>
                  <Label Text="~~"/>
            </StackLayout>
    </DataTemplate>
</ListView.HeaderTemplate>

答案 1 :(得分:0)

我一直有同样的问题。是什么解决了这个问题,我在视图模型构造函数中实例化了我绑定的对象。我相信这是因为我绑定到使用<Label Text="{Binding .}"/>绑定时为null的对象。

相关问题