title: Access bound object in UserControl code behind with DependencyProperty
body: <p>I am having trouble setting a property of a custom user control using a DependencyProperty through databinding on the parent UserControl.</p>
  
  <p>Here is the code for my custom UserControl:</p>
  
  <pre><code>public partial class UserEntityControl : UserControl
  {
      public static readonly DependencyProperty EntityProperty =  DependencyProperty.Register("Entity",
          typeof(Entity), typeof(UserEntityControl));
  
      public Entity Entity
      {
          get
          {
              return (Entity)GetValue(EntityProperty);
          }
          set
          {
              SetValue(EntityProperty, value);
          }
      }
  
      public UserEntityControl()
      {
          InitializeComponent();
          PopulateWithEntities(this.Entity);
      }
  }
  </code></pre>
  
  <p>I want access to the Entity property in the code behind because that will dynamically build the user control based on values stored in the Entity. The problem that I am having is that the Entity property is never set.</p>
  
  <p>Here is how I am setting up the binding in the parent user control:</p>
  
  <pre><code>&lt;ListBox Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding SearchResults}"     x:Name="SearchResults_List"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;!--&lt;views:SearchResult&gt;&lt;/views:SearchResult&gt;--&gt;
              &lt;eb:UserEntityControl  Entity="{Binding}" &gt;&lt;/eb:UserEntityControl&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>I am setting the ItemsSource of the ListBox to SearchResults, which is an Observable Collection of Entities (The same type as Entity on the custom UserControl).</p>
  
  <p>I am not getting any runtime binding errors in the debug output window. I just cannot set the value of the Entity property. Any ideas?</p>