title: Binding ItemsSource programmatically
body: <p>What is the equivalent of this in c# code?</p>
  
  <pre><code>&lt;ListView
      x:Name="taskItemListView"
      DataContext="{Binding SelectedItem, ElementName=itemListView}"
      ItemsSource="{Binding taskItems}"&gt;
  ...
  &lt;/ListView&gt;
  </code></pre>
  
  <p>I've tried the following code, but it doesn't seem to work...</p>
  
  <pre><code>Binding b = new Binding();
  b.Path = new PropertyPath("taskItems");
  
  DependencyProperty dp = DependencyProperty.Register("itemsSource", typeof(object), typeof(object), null);
  BindingOperations.SetBinding(taskItemListView, dp, b);
  </code></pre>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Based on @sa_ddam213's answer, this worked:</p>
  
  <pre><code>Binding dataContextBinding = new Binding();
  dataContextBinding.Path = new PropertyPath("SelectedItem");
  dataContextBinding.Source = itemListView;
  BindingOperations.SetBinding(taskItemListView, ListView.DataContextProperty, dataContextBinding );
  
  Binding sourceBinding = new Binding();
  sourceBinding.Path = new PropertyPath("taskItems");
  BindingOperations.SetBinding(taskItemListView, ListView.ItemsSourceProperty, sourceBinding );
  </code></pre>