Philippe Lavoie
Philippe Lavoie

Reputation: 2593

WPF Binding : Object in a object

I have a form in WPF with 2 textbox :

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

and I have 2 class :

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

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

The Name property binds fine. But the Number property of the Address object inside the Contact object does not binds. What I'm doing wrong ?

Upvotes: 3

Views: 2850

Answers (3)

Muhammad Hasan Khan
Muhammad Hasan Khan

Reputation: 35126

You may not be implementing INotifyPropertyChanged in the classes and may be assigning the value after the binding. If you try Snoop http://snoopwpf.codeplex.com/ you can find out the exact problem.

Upvotes: 3

Ian
Ian

Reputation: 4909

There's a few good resources for debugging bindings here. I've used the converter method detailed very successfully.

Upvotes: 1

Pavlo Glazkov
Pavlo Glazkov

Reputation: 20746

Everything looks fine, check that the Address property is not null when binding occurs. Also you can check Visual Studio output window while under debug to see whether there are any binding errors.

Upvotes: 2

Related Questions