WPF 中的数据绑定
我有一个 A 类的实例;
class A
{
ICollection<B> collec.....
}
class B
{
C propC....;
}
class C
{
string Name;
}
我将实例作为数据上下文传递给窗口,并将 collec 设置为网格的 ItemCollectionSource。是否可以在DataGrid中显示C的Name属性。如果我给出绑定属性,则设置其他属性。
谢谢..
I have a an instance of class A;
class A
{
ICollection<B> collec.....
}
class B
{
C propC....;
}
class C
{
string Name;
}
I pass instance as the datacontext to a Window and had set collec as ItemCollectionSource for the grid. Is it possible to display the Name property of C in the DataGrid. Other properties are set if i give the Binding Property.
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嵌套属性可以在绑定表达式中引用,这样......
我假设
propC
确实是一个公开暴露的属性。您还需要确保Name
也是公开公开的属性。Nested properties can be referenced within a binding expression as such...
...where I'm assuming
propC
is indeed a publicly exposed property. You will also need to make sure thatName
is also a publicly exposed property.将
C.Name
设为属性而不是字段,并绑定到 propC.NameMake
C.Name
a property rather than a field, and bind on propC.Name您当前正在使用私有字段,请尝试使用公共属性。
You are using private fields currently, try it with a public property instead.