title: creating a reusable user control in WPF
body: <p>In the (fairly large) LOB application we are building with WPF for UI we have a lot of viewmodels that contain the same kind of data sub-object. For example, there are a lot of addresses </p>
  
  <pre><code>public class AddressViewModel : INotifyPropertyChanged
  {
  
     public string City {...}
     public string ZipCode {...}
     public string Address {...}
     public string Number {...}
  
    // INPC logic omitted 
  }
  </code></pre>
  
  <p>scattered among business objects:</p>
  
  <pre><code>public class CustomerViewModel : INotifyPropertyChanged
  {
       public string Name {...}
       public AddressViewModel BillingAddress {...}
       public AddressViewModel DeliveryAddress {...}
       /*
       ...
       */
  }
  </code></pre>
  
  <p>is it possible to build a reusable custom User Control which we can bind to any address sub-object?</p>
  
  <p>In a view (possibly another custom user control) designed to edit customer details we would like to put a custom control like this</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;UserControl x:Class="OurApp.View.AddressEditor"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               mc:Ignorable="d" 
               d:DesignHeight="300" d:DesignWidth="300"&gt;
      &lt;Grid&gt;
  
          &lt;TextBox x:Name="ZipCode" Text="{Binding Path=ZipCode, UpdateSourceTrigger = PropertyChanged}" Validation.ErrorTemplate="{x:Null}" HorizontalAlignment="Left" Height="23" Margin="10,19,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="120" /&gt;
  
           &lt;!-- other fields for the rest of AddressViewModel properties--&gt;
  
      &lt;/Grid&gt;
  
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>that we can simply use like this in a view bound to a CustomerViewModel instance</p>
  
  <pre class="lang-xml prettyprint-override"><code> &lt;TextBox x:Name="Name" Text="{Binding Path=Name, UpdateSourceTrigger = PropertyChanged}" Validation.ErrorTemplate="{x:Null}" /&gt;
  
  &lt;AddressEditor SomeProperty="{something that points to BillingAddress}" /&gt;
  &lt;AddressEditor SomeProperty="{something that points to DeliveryAddress}" /&gt;
  </code></pre>
  
  <p>What is the correct way to do this? We tried to point the binding to BillingAddress but we did not find a working way...</p>
  
  <p>Thanks in advance for any contribution,</p>