gpt4 book ai didi

wpf - CollectionViewSource 源属性上的集合绑定(bind)

转载 作者:行者123 更新时间:2023-12-01 01:32:16 24 4
gpt4 key购买 nike

我有一个 CollectionViewSourceItemsSource我的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'


怎么了?我怎样才能做到这一点?

最佳答案

我解决! ...这样:

      Dim _cvs as CollectionViewSource = New CollectionViewSource
Dim bindSource = New Binding() With {
.Source = Me.DataContext
.Path = New PropertyPath("MyObservableCollection"),
.Mode = BindingMode.OneWay }
BindingOperations.SetBinding(cvs, CollectionViewSource.SourceProperty, bindSource)

关于wpf - CollectionViewSource 源属性上的集合绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4031498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com