WPF数据绑定:一个对象中的对象

3

我有一个WPF表单,其中包含2个文本框:

<TextBox Name="txtName" Text="{Binding Contact.Name}"/>
<TextBox Name="txtAddressNumber" Text="{Binding Contact.Address.Number}"/>

我有两个类:

public class ContactEntity
{
  public string Name {get;set;}
  public AddressEntity Address {get;set;}
}

public class AddressEntity
{
  public int Number {get;set}
}

Name属性绑定正常。但是Contact对象内部的Address对象的Number属性没有绑定。我做错了什么?

3个回答

3
你可能没有在类中实现INotifyPropertyChanged,并且可能在绑定后分配了值。如果你尝试使用Snoop http://snoopwpf.codeplex.com/,你可以找到确切的问题。

我的ContactEntity缺少INotifyPropertyChanged。它在我的ViewModel中,但不在我的Entity中。非常感谢! - Philippe Lavoie

2

一切看起来都很好,检查绑定发生时地址属性是否为空。同时,您可以在调试期间检查Visual Studio输出窗口,以查看是否有任何绑定错误。


1

有一些很好的调试绑定的资源在这里。我已经非常成功地使用了详细介绍的转换器方法。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接