2011-02-04 68 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。我已經非常成功地使用了轉換器方法。