I was looking at creating a common control that I will be able to reuse on my pages: an AddressControl which has Address1, Address2, City, State, Zip, etc...
Originally I just created a class (AddressEntity
) that contained all these items and implemented INotifyPropertyChanged
. I included that class as a DependencyProperty in my Code-Behind for the AddressControl and used it as the DataContext for the bindings to its properties.
Then, someone said my code was ugly and I should look into MVVM. Looking at it, I assume that:
- AddressEntity.cs will just be a container of data (i.e. Address1, Address2, etc.) and members (i.e. Clone, ToString, etc.)
- I need some AddressViewModel to wrap my AddressEntity in and provide the PropertyNotification Changes, Validation, etc.
- I need to somehow have a "View" for this.
The problem is every example I've ever seen has a UserControl as the View and not a CustomControl. Before I delve too deep into this...
- Is it possible to use MVVM + Custom Controls for this example?
- Is it pretty much the same thing (UserControl vs CustomControl) as the View with the exception of primary differences of UserControl vs CustomControl? Basically, is my CustomControl really just a View?
References: HE MODEL-VIEW-VIEWMODEL (MVVM) DESIGN PATTERN FOR WPF