I have a working ListView like this
<ListView Name="passageListView" ItemsSource="{Binding Path=Passages, NotifyOnTargetUpdated=True}" TargetUpdated="PassageListViewTargetUpdated">
where Passages is an ObservableCollection<>.
Now, how I do the same binding in code? (note that NotifyOnTargetUpdated=True has to be set)
I have tried to assign a Binding to passageListView.ItemsSource but this is not allowed and I can’t use SetBinding() since passageListView.ItemsSourceis not a DependencyProperty?
Any ideas?
try this in the constructor of the control where the
ListViewis:If the DataContext is set properly, this should work.
The DependencyProperty could also be
ItemsControl.ItemsSourceProperty, because that is the base class.