Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Binding : Object in a object

Tags:

binding

wpf

xaml

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 ?

like image 748
Philippe Lavoie Avatar asked Dec 10 '25 04:12

Philippe Lavoie


2 Answers

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.

like image 86
Muhammad Hasan Khan Avatar answered Dec 12 '25 18:12

Muhammad Hasan Khan


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.

like image 36
Pavlo Glazkov Avatar answered Dec 12 '25 19:12

Pavlo Glazkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!