I seem to be stuck. Is there a way to export Application.Current of a Silverlight project using MEF, so that when I load .XAP (my Silverlight component project) file I had access to the App of that .xap?
Asked
Active
Viewed 140 times
2 Answers
1
Try this:
Container.ComposeExportedValue(Application.Current);
where Container
is MEF's CompositionContainer
.

Pavlo Glazkov
- 20,498
- 3
- 58
- 71
1
There isn't really a need for this. Since Application.Current is already a singleton, it's going to exist once your .xap is loaded in any case. You shouldn't need to export it via MEF - your component will already be able to access it directly.

Reed Copsey
- 554,122
- 78
- 1,158
- 1,373
-
I'm really new to MEF, so sorry if my question seems silly. I'm still trying to resolve the [following problem](http://stackoverflow.com/questions/5182917/application-startup-doesnt-get-called-when-i-load-xap-dynamically-with-mef). When I call Application.Current, I get access to the mail App, that dynamically loads my .xap, not the imported one – Masha Mar 04 '11 at 17:45
-
@Masha: There is only a single Application.Current at a time in an application. If you're dynamically importing a xap that's intended to be run standalone, it's "application" startup logic won't execute. You should refactor that into something where you can explicitly call it post-composition, if that's your goal. – Reed Copsey Mar 04 '11 at 17:48