I'm trying to set a TwoWay binding to a combo box using only a selection of a collection's objects. Currently, everything works out ok if I just want to bind everything in the colelction, but in the example class below, what if I only want to show items where Active=True? I can filter the items using LINQ like ItemsSource = FROM x IN Coll WHERE x.Active=True but then I lose the TwoWay binding. Ie, if the name or the active state in the source is updated from elsewhere, the combo box does not automatically update.
Is the possible to do? If not, does anyone who has had to deal with this have some suggestions?
'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