Let's say we have a location control that is bound to a location object like so:
<TextBox Text="{Binding Path=Address1}"/>
<TextBox Text="{Binding Path=Address2}"/>
<runtime:LocationControl x:Name="ClientLocation" MinWidth="200" />
I've seen a bunch of examples where DependencyProperties have to be implemented on the LocationControl in order to bind the control to your data. An easier way seems to be to listen to the DataContextChanged event of the top level element that has it's DataContext set. In my code, I set the DataContext of the actual control, so my code looks like this:
public Client()
{
InitializeComponent();
this.DataContextChanged +=
new DependencyPropertyChangedEventHandler(Client_DataContextChanged);
}
void Client_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
this.ClientLocation.DataContext =
((Entities.Client)this.DataContext).Location;
}
Now when the data bindings change on the Client control, my Location control will also reflect the new data.