DataGrid 绑定类型问题
这是我的设置。我有以下 BusinessObject 类
BaseClass
InheritClassA : BaseClass
InheritClassB : BaseClass
InheritClassC : BaseClass
我也有以下字典
Dictionary<classType is a String, ObservableCollection<BaseClass>>
我希望能够在我的转换器中,根据我选择的对象类型,返回正确的 ObservableCollection,以便我可以将其绑定到我的数据网格,并自动生成列,以便我可以在网格上查看我的所有属性。
但是,当我刚刚将集合检索为 BaseClass 时,它只显示基类的列。我认为这是因为 ObservableCollection 的类型是基类的类型,而不是特定于 InheritClassA/InheritClassB/InheritClassC
有没有办法动态创建 ObservableCollection 的类型?那么我可以创建 ObservableCollection 并向其中分配强制转换值吗?
是否有正确的方法将其绑定到我的数据网格,以便我可以查看继承类的属性?
非常感谢,
Here's my setup. I have the following BusinessObject classes
BaseClass
InheritClassA : BaseClass
InheritClassB : BaseClass
InheritClassC : BaseClass
I also have the following dictionary
Dictionary<classType is a String, ObservableCollection<BaseClass>>
I want to be able to, in my converter, base on the type of object I select, return the proper ObservableCollection so I can bind it to my datagrid, and autoGenerateColumn on so I can view all my properties on the grid.
However, when i just retrieve my collection back as BaseClass, it only shows me the columns for the base class. I think this is because the Type for the ObservableCollection is type of baseClass and not specific to InheritClassA/InheritClassB/InheritClassC
Is there a way to dynamically create a ObservableCollection's Type? So I can create ObservableCollection and assign casted values into it?
Is there a proper way to bind it to my datagrid so I can view the properties for the inherit class?
Thanks very much ,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个字典,其值类型为
Object
而不是BaseClass
。然后,您可以添加具体的ObservableCollection
,绑定将按照您的预期工作:如果您想更具限制性,请将其声明为
Dictionary<;字符串,IEnumerable>
Create a dictionary that has as the value-type an
Object
and not aBaseClass
. Then you can add the concreteObservableCollection<InheritClass[A,B,C]>
and the binding will work like you expect:If you want to be more restrictive, declare it as
Dictionary<string,IEnumerable>