Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to get listview header context in item

$
0
0

Hi,
I am using a grouped ListView and want to show information of the group header displayed in the item.

Here is my xaml code:

<ListView ItemsSource="{Binding ParentList}" IsGroupingEnabled="true">
  <ListView.GroupHeaderTemplate>
    <DataTemplate>
      <ViewCell>
        <StackLayout>
          <Label Text="{Binding ParentTitle}"/>
        </StackLayout>
      </ViewCell>
    </DataTemplate>
  </ListView.GroupHeaderTemplate>

  <ListView.ItemTemplate>
    <DataTemplate>
      <ViewCell>
        <StackLayout>
          <Label Text="{Binding ParentTitle}"/> <!-- Here I want to get the GroupHeader Context -->
          <Label Text="{Binding ChildTitle}"/>
        </StackLayout>
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

Here is my Parent class:

public class Parent : ObservableCollection<Child>
{
  public ObservableCollection<Child> ChildList => this;
  public String ParentTitle { get; set; }
}

Here is my Child class:

public class Child
  public String ChildTitle { get; set; }
}

I already tried setting a x:Name on the GroupHeader but it is not unique so the item can not find it.

Can anyone please help?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>