WPF 中的数据绑定

发布于 2024-10-09 18:00:44 字数 273 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丿*梦醉红颜 2024-10-16 18:00:44

嵌套属性可以在绑定表达式中引用,这样......

<TextBlock Text={Binding propC.Name} />

我假设 propC 确实是一个公开暴露的属性。您还需要确保 Name 也是公开公开的属性。

Nested properties can be referenced within a binding expression as such...

<TextBlock Text={Binding propC.Name} />

...where I'm assuming propC is indeed a publicly exposed property. You will also need to make sure that Name is also a publicly exposed property.

萌无敌 2024-10-16 18:00:44

C.Name 设为属性而不是字段,并绑定到 propC.Name

Make C.Name a property rather than a field, and bind on propC.Name

杀お生予夺 2024-10-16 18:00:44

您当前正在使用私有字段,请尝试使用公共属性。

class C
{
     public string Name {get;set;}
}

You are using private fields currently, try it with a public property instead.

class C
{
     public string Name {get;set;}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文