In a WPF application following MVVM pattern I have a Customer class which has a property of type Address.
In my CustomerViewModel I create a new datacontext and get my customer with this, I also have my bog standard properties, forename, surname, etc… but how would I hook my address object into the customer view model? Do I:
- Simply replicate all the address properties in my customerVM
- Create an AddressViewModel and hold a reference to this as my
Address property? If this is the way how would I get the datacontext
into the AddressViewModel instance?
I would choose plan B.
create AddressVM, add it as a dependency property to CustomerVM, and use it like:
you don’t need to set DataContext for subclasses. you have access to them via ‘.’