我有一个CollectionViewSource
我ItemsSource
的DataGrid
. 在Window.Resources
我有这个定义:
<CollectionViewSource x:Key="ItemsPoolCollectionView"
Source="{Binding Path=MyObservableCollection, Mode=OneWay}" />
现在,我想从代码中生成相同的定义,所以我这样做了:
Dim _cvs as CollectionViewSource = New CollectionViewSource
Dim bindSource = New Binding() With {
.Path = New PropertyPath("MyObservableCollection"),
.Mode = BindingMode.OneWay }
_cvs.SetValue(CollectionViewSource.SourceProperty, bindSource)
但我在最后一条语句中有这个错误:
'System.Windows.Data.Binding' is not a valid value for property 'Source'
怎么了?我怎样才能做到这一点?