How do I solve binding multiple views to a ObservableCollection?

Topics: Conventions, Extensibility, Framework Services
Mar 16, 2013 at 10:43 AM

I have a situation where I have a normal property of type ObservableCollection<SpecificViewType> on a Control I wish to bind to with CM.

It is a 3rd party lib and although I have the source code, I would prefer not to change anything.

I cannot get multiple view to be added to that collection by using CM. Is it possible or should that property be a DependencyProperty for that (I think so)?

So I did some coding to get around it but now, CM has lost its 'grip' and none of the CM features work inside those views I added to the collection.

Is there any way to register the view back in CM so it'll start working again?
Or to have items added to that view collection?

Mar 16, 2013 at 3:34 PM
Do the specific view types have some sort of a concrete implementation that could be exported and then imported into your collection? Assuming you are using MEF or some container.
Mar 16, 2013 at 6:17 PM
They are Flyout 'windows' - a bit like TabItems. The collection property (Flyouts) can be set (its public). I now have two views -one for each Flyout window I need- that derive from the Flyout 'content' control (like a UserControl) and each implement their unique layout. I already export their ViewModels to MEF not the controls them selves.

I do not understand how I could Import them into a collection I don't own...?
Mar 17, 2013 at 11:15 PM
Edited Mar 17, 2013 at 11:17 PM
I can't think of any way to do that in CM at present. Conventions possible but that would be an incredible amount of monkey work to wedge your viewmodels into the collection of the control (might have to do it in the view, which might end up being counter mvvm testability in this case).

You using view first or viewmodel first?
Mar 18, 2013 at 6:17 AM
I work ViewModel first. But in this case I thought perhaps View first would work...? Getting these views declared in xaml and binding the VM to it? Is that what the Model attached property is for?