What is the “best” (or the most-often-used) approach when binding a complex class to a user control for re-use?
I am trying to create some reusable libraries for classes, and I am not sure which approach I should use. Example: I want to create an Address library that defines and Address class (with properties Line1, Line2 etc.), it’s validation logic and an AddressControl which acts as the viewer/editor with bound fields for each property.
In use I might have a customer class with BillingAddress, DeliveryAddress properties and I would want to bind these in my customer control thus:
<addressLib:AddressControl [xxx]="{Binding BillingAddress}" />
So the question is what do I put in XXX?
Initially I thought of creating a DependencyProperty ‘Address’ on the control:
<addressLib:AddressControl Address="{Binding BillingAddress}" />
But now I am thinking surely I could just use the existing DataContext property?
<addressLib:AddressControl DataContext="{Binding BillingAddress}" />
Is this the best approach? Are there any issues e.g. updates or NotifyPropertyChange issues?
many thanks for your help!
One difference to remember is that with dependency property you get change notification and with datacontext you don’t (at least not untill SL5 is out)