0
Answer

Return a collectionviewsource with codebehind.

D S

D S

10y
10.2k
1

Hello, I'm trying to return a grouped observablecollection but all I get in my xaml is "MyProject.Model.KeyedList'2(|System.String.MyProject.model".
It doesn't seem to understand that it's data being sent.

app.xaml

<ListView ItemsSource="{Binding Path=CatSorted}" > 
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}" Foreground="White" />
</DataTemplate>  
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</Listview>

myViewModel.xaml.cs

private CollectionViewSource catSorted; public ICollectionView CatSorted
{
get {

if (catSorted == null)

{

catSorted = new CollectionViewSource();

var GroupedCatsByDate = from c in cats.GetCats() group c by e.CatDate into groupedByDate

select new KeyedList<string, CatModel>(groupedByDate);

catSorted.Source = new ObservableCollection<KeyedList<string, CatModel>>(groupedByDate);

}

return catSorted.View; }

}