D S

D S

  • NA
  • 5
  • 13.4k

Return a collectionviewsource with codebehind.

Jul 20 2014 3:46 AM

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; }

}