WPF binding: object in object

I have a form in WPF with 2 text fields:

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

and I have class 2:

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 the penalty. But the Number property of the Address object inside the Contact object is not bound. What am I doing wrong?

+3
source share
3 answers

Perhaps you do not implement INotifyPropertyChanged in classes and can assign a value after binding. If you try Snoop http://snoopwpf.codeplex.com/ , you can find out the exact problem.

+3
source

, , Address null . Visual Studio , , - .

+2

There are some good resources for debugging bindings here . I have very successfully used the converter method.

+1
source

Source: https://habr.com/ru/post/1789999/


All Articles