1: private CompositionContainer _container;
2: private AggregateCatalog ac;
3: private PackageCatalog pc;
4:
5: public MainPage()
6: {
7: ac = new AggregateCatalog();
8: pc = new PackageCatalog();
9: ac.Catalogs.Add(pc);
10: _container = new CompositionContainer(ac);
11:
12: Views = new ObservableCollection<Lazy<IModule>>();
13:
14: InitializeComponent();
15:
16: Views.CollectionChanged += new NotifyCollectionChangedEventHandler(Views_CollectionChanged);
17:
18: Package.DownloadPackageAsync(new Uri("Module1.xap", UriKind.Relative), completed);
19: Package.DownloadPackageAsync(new Uri("Module2.xap", UriKind.Relative), completed);
20: }
21:
22: private void completed(AsyncCompletedEventArgs e, Package p)
23: {
24: if (!e.Cancelled && e.Error == null)
25: {
26: pc.AddPackage(p);
27: CompositionBatch batch = new CompositionBatch();
28: batch.AddPart(this);
29: batch.AddExportedValue<CompositionContainer>(_container);
30: _container.Compose(batch);
31: }
32: }
33:
34: void Views_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
35: {
36: this.stack.Children.Clear();
37: foreach (Lazy<IModule> view in Views)
38: this.stack.Children.Add(view.Value as UserControl);
39: }
40:
41: [ImportMany(AllowRecomposition = true)]
42: public ObservableCollection<Lazy<IModule>> Views { get; private set; }