Note that there are some explanatory texts on larger screens.

plurals
  1. POMEF + SL4 question
    text
    copied!<p>I'm working on an app in the Silverlight 4 RC and i'm taking the oppertunity to learn MEF for handling plugin controls. I've got it working in a pretty basic manor, but it's not exactly tidy and I know there is a better way of importing multiple xap's.</p> <p>Essentially, in the App.xaml of my host app, I've got the following telling MEF to load my xap's:</p> <pre><code>AggregateCatalog catalog = new AggregateCatalog(); DeploymentCatalog c1 = new DeploymentCatalog(new Uri("TestPlugInA.xap", UriKind.Relative)); DeploymentCatalog c2 = new DeploymentCatalog(new Uri("TestPlugInB.xap", UriKind.Relative)); catalog.Catalogs.Add(c1); catalog.Catalogs.Add(c2); CompositionHost.Initialize(catalog); c1.DownloadAsync(); c2.DownloadAsync(); </code></pre> <p>I'm sure I'm not using the AggregateCatalog fully here and I need to be able to load any xap's that might be in the directory, not just hardcoding Uri's obviously....</p> <p>Also, in the MainPage.xaml.cs in the host I have the following collection which MEF puts the plugin's into:</p> <pre><code>[ImportMany(AllowRecomposition = true)] public ObservableCollection&lt;IPlugInApp&gt; PlugIns { get; set; } </code></pre> <p>Again, this works, but I'm pretty sure I'm using ImportMany incorrectly....</p> <p>Finally, the MainPage.xaml.cs file implements IPartImportsSatisfiedNotification and I have the following for handling the plugin's once loaded:</p> <pre><code>public void OnImportsSatisfied() { sp.Children.Clear(); foreach (IPlugInApp plugIn in PlugIns) { if (plugIn != null) sp.Children.Add(plugIn.GetUserControl()); } } </code></pre> <p>This works, but it seems filthy that it runs n times (n being the number of xap's to load). I'm having to call sp.Children.Clear() as if I don't, when loading the 2 plugin's, my stack panel is populated as follows:</p> <p>TestPlugIn A TestPlugIn A TestPlugIn B</p> <p>I'm clearly missing something here. Can anyone point out what I should be doing? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload