stiank81
stiank81

Reputation: 25686

Binding ObservableCollection<Foo> to ObservableCollection<object>

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..

Upvotes: 1

Views: 409

Answers (2)

Sebastian Edelmeier
Sebastian Edelmeier

Reputation: 4157

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.

Upvotes: 0

HCL
HCL

Reputation: 36775

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.

Upvotes: 1

Related Questions