title: WPF binding multiple controls to different datacontexts
body: <p>I have a scenario where I don't really know how to bind data to controls hosted in a UserControl to multiple datacontexts.</p>
  
  <p>The data i want to bind comes from 2 classes</p>
  
  <pre><code>UserInfo, UserExtendedInfo
  </code></pre>
  
  <p>The datacontext of the UserControl is set to UserInfo so i can bind most controls easily doing the following </p>
  
  <pre><code>&lt;Label Name="LblEmail" Text="{Binding Email}" /&gt;
  </code></pre>
  
  <p>However I don't know how to bind properties from the UserExtendedInfo class easily. My initial thought was to set the datacontext of each control that want's to use the data from UserExtendedInfo so i could do the same. But this seems cumbersome as i would have to manually assign each one indivdually. The data for UserExtendedInfo must be fetched from the database each time the UserControl becomes visible so that it doesn't get out of sync. </p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Label Name="LblTest" Text="{Binding Locale}" /&gt;
  </code></pre>
  
  <p>Code Behind:</p>
  
  <pre><code>Private Sub UserManager_IsVisibleChanged(ByVal sender As System.Object, ByVal e As System.Windows.DependencyPropertyChangedEventArgs)  
          If DirectCast(e.NewValue, Boolean) Then
              Dim user As UserInfo = DirectCast(DataContext, UserInfo)
  
              If user IsNot Nothing Then
                  Dim usrExt As UserExtenedInfo = UserController.GetUserExtended(user.userID)
  
                  LblTest.DataContext = usrExt
              Else
                  Throw New ArgumentException("UserId doesn't exist or is less than 1")
              End If
          End If
      End Sub
  </code></pre>