How to import interfaces into exported widgets?

Jul 13, 2010 at 5:31 AM


I run in a bit of a problem here. I have simple silverlight3 app that imports all available UI elements used for navigation.

It works fine until I have to import some interfaces into those widgets. And because MEF does not create those instances (silverlight navigation does) it cannot satisfy imports. At the same time in those widgets I cannot use 'CompositionInitializer.SatisfyImports(this);' because widgets have [Export] attribute. Any ideas how I can solve this ?

[PageMetadata(Content="trial", NavigateUri="/TrialPage")]
    public partial class TrialPage : Page, IPartImportsSatisfiedNotification
        private IUserProvider _provider;

        public TrialPage()


        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)

        public void OnImportsSatisfied()
            // never being called !!
            UserName.Text = _provider.CurrentUser;

Jul 16, 2010 at 3:50 PM

If the Page is being created externally you should use CompositionInitializer. Now, regarding the widgets, that's more complex. If it's own by the navigation infrastructure, you need to find a way to export them manually. Having the export attribute wont do anything.