Linking two observed collections to each other

I have two properties of type ObservableCollection (in separate projects); What I want to do is bind the two using reflection and SetBinding, like this -

//Get the PropertyDescriptor for first collection property
PropertyDescriptor relatedPropertyDesc = prop.Find(firstCollPropName, false);
Binding relatedPropBinding = new Binding(relatedPropertyDesc.Name);
relatedPropBinding.Source = this.SelectedItem;
relatedPropBinding.Mode = BindingMode.TwoWay;
//Bind the second collection property using binding created above
propItem.SetBinding(MyItem.SecondCollProperty, relatedPropBinding);

This SecondCollProperty is then bound to the Items ComboBox element.

Thus, it works correctly, the values ​​represented in firstCollProperty are displayed correctly in combobox; but , if some changes are made to firstCollProperty at run time, then they are not reflected in the ComboBox! (adding new items or creating a new collection object).

Changes are reflected correctly after updating the binding (execution of the above code again).

My question is - If two ObservableCollections are related to each other, why aren't any changes in the first reflected in the others? but the same thing works for string or double type properties.

Is there any way to achieve this?

+3
source share
1 answer

- . , , CLinq, Bindable Linq Obtics. . . , ( IObservableCollection) .

0

Source: https://habr.com/ru/post/1774053/


All Articles