我正在尝试仅使用选择的集合对象将 TwoWay 绑定设置到组合框。目前,如果我只想绑定集合中的所有内容,一切正常,但在下面的示例类中,如果我只想显示 Active=True 的项目怎么办?我可以使用 LINQ 过滤项目,例如 ItemsSource = FROM x IN Coll WHERE x.Active=True 但随后我失去了 TwoWay 绑定。即,如果源中的名称或活动状态是从其他地方更新的,则组合框不会自动更新。
有可能吗?如果没有,是否有人不得不处理这个问题有一些建议?
'The Class
Public Class Test
Implements ComponentModel.INotifyPropertyChanged
Private _Name As String
Private _Active As Boolean
Public Sub New(Name As String, Active As Boolean)
_Name=Name
_Active=Active
End Sub
Public Property Name() As String
End Class
'Declare a Collection and add some Tests, then bind to Cbo in Page Load
Dim Coll As New ObservableCollection
Coll.Add(New Test("Test1", True))
Coll.Add(New Test("Test2", False))
Coll.Add(New Test("Test3", True))
TheComboBox.ItemsSource=Coll