I'm having difficulty understanding how to bind to nested properties of an exposed model in a viewmodel using MVVM Light.
I have the following set up and the 'StreetAddress' component is not updating when a service updates the Address:
Address Model:
public class Address : ObservableObject
{
private uint _streetNumber;
public uint StreetNumber
{
get
{
return _streetNumber;
}
set
{
Set(ref _address, value, nameof(StreetNumber));
}
}
}
Person Model:
public class Person : ObservableObject
{
private Address _address;
public Address Address
{
get
{
return _address;
}
set
{
Set(ref _address, value, nameof(Address));
}
}
}
QueryPerson View Model:
public class QueryPersonViewModel : ViewModelBase
{
public Person QueriedPerson { get; set; }
public Address QueriedPersonAddress
{
get
{
return QueriedPerson.Address
}
}
...
}
QueryPerson View snippet:
<Grid DataContext="{Binding QueriedPersonAddress}">
...
<TextBox Text="{Binding StreetNumber, Mode=OneWay}" />
</Grid>
Does the pattern above adhere to MVVM best practices? Is there a better way to bind to nested properties from the view? What would be the reason for the TextBox text to not be updated if the Address setter is called?