Getting Items for Conductor<T>.Collection

Jul 21, 2010 at 1:44 PM

Hi! In my application, I'd like to have a navigating Menu in the ShellView. So I have many VMs, where always one is active. For this purpose I inherit my ShellViewModel from Conductor<IScreen>.Collection.OneActive, which has a BindableCollection Items implemented. I use Mef as IoC, the bootstrapper was built according to the one in the docs. My question is:

How do I get all the ViewModels that inherit from IScreen into the Items-Collection? As the VMs are exported with their Type, and not with a common Interface, I find no way. Is there a "oh-my-god-i-am-so-blind-not-to-see-that"-way? Or do I have to customize Mef? Any hint appreciated!

Thanks in advance, Roland

Jul 21, 2010 at 2:06 PM
Edited Jul 21, 2010 at 2:08 PM

You can actually export a type as multiple interfaces simultaneously. So, you can just add an [Export(typeof(IScreen))] in addition to what you already have. Then you can use an [ImportMany] on your conductor's constructor parameter, like this:


        public YourConductor([ImportMany]IEnumerable<IScreen> screens)

Then, just add them to the Items collection and probably you want to activate one of them by default.


Jul 21, 2010 at 2:22 PM

Woah, thats enlightenment. Works great! Thanks for the quick answer!