System.Linq.GroupBy重点在Silverlight不具约束力 [英] System.Linq.GroupBy Key not binding in silverlight

查看:195
本文介绍了System.Linq.GroupBy重点在Silverlight不具约束力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

list.ItemsSource=db.Templates.GroupBy(t=>t.CategoryName);

在XAML:

<DataTemplate>
   <TextBlock Text="{Binding Key}" />
</DataTemplate>

此代码后。不要显示TextBlock的任何文本。我改变了文本这样的结合

After this code. Don't show any text in TextBlock. I'm changing Text binding like this

<DataTemplate>
   <TextBlock Text="{Binding}" />
</DataTemplate>



的TextBlock这样的 System.Linq.Lookup ^ 2 +分组[显示的文字System.String,Model.Template]

我调试和检查属性。这不是空。

I'm debugging and checking Key property. this is not null.

为什么不绑定的TextBlock?

Why Key don't bind in TextBlock?

如何显示在文本块组标题

How to show group title in Textblock?

推荐答案

嗯? - 不幸的。究其原因是因为 GROUPBY()调用的结果是 System.Linq.Lookup<的实例;,> .Grouping 分组是一个嵌套类的查找<的;,> 类然而分组标记为内部

Hmmm - unfortunate. The reason is because the result of the GroupBy() call is an instance of System.Linq.Lookup<,>.Grouping. Grouping is a nested class of the Lookup<,> class, however Grouping is marked as internal.

安全在Silverlight的限制,不要让你绑定到非公共类型定义的属性,即使这些属性在一个公共接口,类实现的声明。事实上,你要绑定的对象实例是一个非公开的具体类型意味着你只能绑定到任何公开的基地该类型的类的定义的公共属性。

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:

public class MyGrouping {
  public string Key {get; internal set;}
}

list.ItemsSource=db.Templates.GroupBy(t=>t.CategoryName)
                             .Select(g => new MyGrouping { Key = g.Key });

这篇关于System.Linq.GroupBy重点在Silverlight不具约束力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆