list.ItemsSource=db.Templates.GroupBy(t=>t.CategoryName);
in xaml:
<DataTemplate>
<TextBlock Text="{Binding Key}" />
</DataTemplate>
After this code. Don’t show any text in TextBlock. I’m changing Text binding like this
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
TextBlock Text shown like this System.Linq.Lookup^2+Grouping[System.String,Model.Template]
I’m debugging and checking Key property. this is not null.
Why Key don’t bind in TextBlock?
How to show group title in Textblock?
Hmmm – unfortunate. The reason is because the result of the
GroupBy()call is an instance ofSystem.Linq.Lookup<,>.Grouping.Groupingis a nested class of theLookup<,>class, howeverGroupingis marked asinternal.Security restrictions in Silverlight don’t let you bind to properties defined on non-public types, even if those properties are declared in a public interface which the class implements. The fact that the object instance you are binding to is of a non-public concrete type means that you can only bind to public properties defined on any public base classes of that type.
You could build a public shim class to act as a view model for the grouping: