Reputation: 1985
I am trying to use the group header template in xamarin forms I have followed the following article and implemented but no success http://motzcod.es/post/94643411707/enhancing-xamarinforms-listview-with-grouping even took suggestion from here http://www.infinite-x.net/2015/04/08/working-with-the-listview-groupheadertemplate/
if I put GroupDisplayBinding i will get normal style, even though I have template
<ListView.GroupHeaderTemplate>
<ViewCell>
<StackLayout
VerticalOptions="FillAndExpand"
BackgroundColor="#009688">
<Label Text="{Binding Key}" TextColor="White" Margin="10" FontSize="Medium" />
</StackLayout>
</ViewCell>
</ListView.GroupHeaderTemplate>
if I remove GroupDisplayBinding I will get my group class type in the group as shown in this image
collection code
private ObservableCollection<Grouping<string, MFullIssue>> _Issues;
public ObservableCollection<Grouping<string, MFullIssue>> Issues
{
get { return _Issues; }
set { _Issues = value; OnPropertyChanged(); }
}
SthotramService.service.Issues().ContinueWith((t) =>
{
var sorted = from c in t.Result
orderby c.IssueTypeName
group c by c.IssueTypeName
into theGroup
select new Grouping<string, MFullIssue>(theGroup.Key, theGroup);
Issues = new ObservableCollection<Grouping<string, MFullIssue>>(sorted);
});
collection object
public class MFullIssue
{
public int IssueID { get; set; }
public int IssueTypeID { get; set; }
public string Issue { get; set; }
public int DisplayOrder { get; set; }
public bool IsActive { get; set; }
public string IssueTypeName { get; set; }
public string IssueTypeDesc { get; set; }
public List<MResolution> Resolutions { get; set; }
}
grouping class
public class Grouping<K,T>:ObservableCollection<T>
{
public K Key { get; private set; }
public Grouping(K key, IEnumerable<T> items)
{
Key = key;
foreach (var item in items)
{
Items.Add(item);
}
}
}
Upvotes: 2
Views: 5059
Reputation: 11105
Looking at my Grouped ListView code, your GroupHeaderTemplate
needs to be a DataTemplate
. Not sure if that is the root issue but will definitely cause problems later if not:
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
...
Other than that, I do not see any issues with your code so you may need to make sure the groups in your ObservableCollection
look correct.
Upvotes: 3