views:

54

answers:

2

I have a collection ObservableCollection<Foo>, and I want to bind this to a property in a custom controller of type ObservableCollection<object>. However, the bound value never reaches the PropertyCallback, and is hence never set.

Is there a clever way to achieve this binding? I could create an IValueConverter that converts from ObservableCollection<Foo> to ObservableCollection<object>, but that gives new problems..

+1  A: 

As far as I know, there is no automatic conversion. Writing a ValueConverter is an option.

If you have often the need for this specific conversion, maybe a TypeConverter can do what you need. After creating, declare it with the TypeConverterAttribute, then in bindings automatic conversion will be done.

HCL
TypeConverter might be better, but I guess that gives the same problems IValueConverter do? (See referenced question in edit).
stiank81
A: 

I don't think there is a beautiful way of achieving this. You might want to look into Covariance and Contravariance (.Net 4), but it won't work for your object example.

Sebastian Edelmeier