How to display UserControl with all imports satisfied
I am having problems with Silverlight 4 / MEF. I have a basic framework with a Silverlight Navigation application at its core.
Link to image to diagram for clarification
The main application (Desu) contains some pages and controls that export to import. I am dynamically loading controls from Desu.Controls (like imageviewer which I identify with IImageViewer interface) and some pages from Desu.Pages.
The first problem I ran into was dynamically loading pages and being able to navigate through those pages (for example using dummyhttp: //blagh/desutestpage.aspx#/Activation when loading Desu.Pages from xap). I solved it using a custom MetaAttribute and a custom content loader.
Now for the question part: I want to load ImageViewerControl from Desu.Controls to HomePage in Desu. However, I haven't loaded Desu.Controls into a package. When I try to load the control it gives me a CompositionException because it cannot satisfy the ImageViewControl import. I tried to set AllowRecomposition = true, but it didn't help.
So it is possible to load a control without satisfying all imports, and if so, how to do it?
a source to share
So, you want the import to not be satisfied initially, but you want it to be added later?
You were on the right track with AllowRecomposition = true, but you also need to set AllowDefault = true. The property will then be null if the ImageViewerControl is not available and will be set when it becomes available.
a source to share