2012-10-24 45 views
0

結合我有一個工作的ListView這樣設置的ListView的ItemSource代碼

<ListView Name="passageListView" ItemsSource="{Binding Path=Passages, NotifyOnTargetUpdated=True}" TargetUpdated="PassageListViewTargetUpdated"> 

其中PassagesObservableCollection<>

現在,我如何在代碼中做同樣的綁定? (注意NotifyOnTargetUpdated=True必須設置)

我試圖分配BindingpassageListView.ItemsSource,但這是不允許的,我不能使用SetBinding()因爲passageListView.ItemsSource不是DependencyProperty

任何想法?

回答

2

嘗試此在的ListView是控制的構造:

passageListView.SetBinding(ListView.ItemsSourceProperty, 
       new Binding 
         { 
          Path = new PropertyPath("Passages"), 
          NotifyOnTargetUpdated = true 
         }); 

如果DataContext設置正確,這應該工作。
DependencyProperty也可能是ItemsControl.ItemsSourceProperty,因爲那是基類。

相關問題