CollectionViewSource 源属性上的集合绑定
我有一个 CollectionViewSource
作为我的 DataGrid
的 ItemsSource
。在 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”不是属性“Source”的有效值
怎么了?我怎样才能做到这一点?
I've a CollectionViewSource
as ItemsSource
of my DataGrid
. In Window.Resources
I have this definition:
<CollectionViewSource x:Key="ItemsPoolCollectionView"
Source="{Binding Path=MyObservableCollection, Mode=OneWay}" />
now, I would like to produce the same definition from code, so I've done this:
Dim _cvs as CollectionViewSource = New CollectionViewSource
Dim bindSource = New Binding() With {
.Path = New PropertyPath("MyObservableCollection"),
.Mode = BindingMode.OneWay }
_cvs.SetValue(CollectionViewSource.SourceProperty, bindSource)
but I've this error on the last statement:
'System.Windows.Data.Binding' is not a valid value for property 'Source'
What's wrong? How can I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决! ...这样:
I solve! ...in this way:
您不需要绑定
CollectionViewSource
即可使其自动“绑定”;只需直接设置 Source 属性的值即可:(抱歉我生锈的 VB.net)
有关详细信息,请参阅以下论坛帖子:
http://social.msdn .microsoft.com/Forums/en-US/wpf/thread/f44df11b-dfa8-4173-bbc8-051875fce4cc
You don't need to bind a
CollectionViewSource
in order to make it "bind" automatically; just set the value of the Source property directly:(sorry for my rusty VB.net)
For more info, see the following forum post:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f44df11b-dfa8-4173-bbc8-051875fce4cc