If I have 2 layers of grouping, It doesnt respect my sorting in the viewmodel. For example, below code is sorting the view model by datecreated descending and first group is year. Although first element in the list has datecreated with year 2018, my first group in the view is 2017 and 2018 at the bottom. I tried to add data:SortDescriptor as well but it didnt change anything. I expect first group year to be 2018
VIEW:
<sfListView:SfListView x:Name="list"
ItemsSource="{Binding Logs}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}" AllowGroupExpandCollapse="True"
SwipeOffset="250" BackgroundColor="White" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
SelectionMode="Single" ItemSpacing="1" IsStickyHeader="False" IsStickyFooter="False" ItemHolding="list_ItemHolding"
SwipeEnded="ListView_SwipeEnded" Swiping="ListView_Swiping"
AllowSwiping="True" IsEnabled="True" GroupHeaderTemplate="{StaticResource GroupHeaderTemplate}">
<sfListView:SfListView.DataSource>
<data:DataSource>
<data:DataSource.SortDescriptors>
<data:SortDescriptor PropertyName="DateCreated" Direction="Descending"/>
</data:DataSource.SortDescriptors>
<data:DataSource.GroupDescriptors>
<data:GroupDescriptor PropertyName="Year" />
<data:GroupDescriptor PropertyName="WeekNo" />
</data:DataSource.GroupDescriptors>
</data:DataSource>
</sfListView:SfListView.DataSource>
VIEW MODEL:
public ObservableCollection<Log> Logs { get; set; }
Logs = new ObservableCollection<Log>(AllLogs.OrderByDescending(e => e.DateCreated).ToList(););
MODEL:
public class Log
{
public DateTime DateCreated { get; set; }
private int weekNo;
public int WeekNo
{
get
{
if (weekNo == 0)
{
weekNo = Helpers.GetIso8601WeekOfYear(this.DateCreated);
}
return weekNo;
}
set { weekNo = value; }
}
private int year;
public int Year
{
get
{
if (year == 0)
{
year = this.DateCreated.Year;
}
return year;
}
set { year = value; }
}
}