C#コードでこれに相当するものは何ですか?
<ListView
x:Name="taskItemListView"
DataContext="{Binding SelectedItem, ElementName=itemListView}"
ItemsSource="{Binding taskItems}">
...
</ListView>
次のコードを試してみましたが、うまくいかないようです...
Binding b = new Binding();
b.Path = new PropertyPath("taskItems");
DependencyProperty dp = DependencyProperty.Register("itemsSource", typeof(object), typeof(object), null);
BindingOperations.SetBinding(taskItemListView, dp, b);
編集:
@ sa_ddam213の回答に基づいて、これはうまくいきました:
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 );