title: Data Binding in Code Behind C#
body: <p>I have a quite simple question:</p>
  
  <p>I have a  People property whose type is List&lt; Person > and a Person has a Name and Surname.
  I want to show the Name on my listBoxPerson and I want to make binding operations in code behind - don't want to use ItemsSource property-
  Here is my code snippet:</p>
  
  <pre><code>Binding userBinding = new Binding();
          userBinding.Source =People;
          userBinding.Path = new PropertyPath("Person.Name");
          listBoxPerson.SetBinding(ContentProperty, userBinding);
  </code></pre>
  
  <p>and here is my xaml code:</p>
  
  <pre><code> &lt; ListBox Height="303" HorizontalAlignment="Left" Margin="12,108,0,0" Name="listBoxPerson" VerticalAlignment="Top" Width="234" &gt;
  
          &lt; ListBox.Resources &gt;
              &lt; ObjectDataProvider x:Key="UserData" ObjectType="local:Person"/ &gt;
          &lt; /ListBox.Resources &gt;
          &lt; ListBox.ItemTemplate &gt;
              &lt; DataTemplate &gt;
                  &lt; Label Content="{Binding Path=Name}" &gt;&lt;/Label  &gt;
              &lt; /DataTemplate &gt;
          &lt; /ListBox.ItemTemplate &gt;
      &lt; /ListBox &gt;
  </code></pre>
  
  <p>this works when I write </p>
  
  <pre><code>listboxPerson.ItemsSource= People;
  </code></pre>
  
  <p>but there is nobody listed with the first given code. I am confused on how to solve this binding problem, and will be pleased with any help=) </p>