2011-02-04 67 views
3

我有一个表格中WPF与2文本框:WPF绑定:对象在对象

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

和我有2类:

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

您可能不会在类中实现INotifyPropertyChanged,并可能在绑定后分配值。如果您尝试Snoop http://snoopwpf.codeplex.com/,则可以找出确切的问题。

+0

我在我的ContactEntity中缺少INotifyPropertyChanged。它在我的ViewModel中,但不在我的实体中。非常感谢 ! – 2011-02-04 15:49:49

2

一切看起来不错,检查绑定发生时,地址属性不为空。您也可以在调试时检查Visual Studio输出窗口,以查看是否存在任何绑定错误。

1

有几个很好的资源来调试绑定here。我已经非常成功地使用了转换器方法。