0
votes

I'm new to prism and trying to figure out how to pass a object reference into a WPF class library (Prism and MEF) from host applcation.

Thanks!

In my host app, a button click invokes the WPF class library:

public override void OnClick()
    {
        //need to pass some object reference into 
        TestButtonBootstrapper bootstrapper = new TestButtonBootstrapper();
        bootstrapper.Run();


    }

My bootstrapper:

protected override void InitializeShell()
    {
        base.InitializeShell();

        if (System.Windows.Application.Current == null)
        {
            new System.Windows.Application();
        }
        System.Windows.Application.Current.MainWindow = (Shell)this.Shell;
        System.Windows.Application.Current.MainWindow.Show();
        System.Windows.Application.Current.MainWindow.Height = 600;
        System.Windows.Application.Current.MainWindow.Width = 250;

        //Application.Current.MainWindow = (Shell)this.Shell;
        //Application.Current.MainWindow.Show();
    }
1
To make this question more clear, give us some information about the type of object you are trying to pass unto the Prism application from the hosting application. - Anderson Imes

1 Answers

0
votes

In Prism, the Bootstrapper is intended to launch your main executable and provide the wiring between the Host application and the composed modules.

In your App.xaml.cs, change the start up code so that you instantiate and run your bootstrapper.

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        new MyBootstrapper().Run();
    }
}

Be sure to remove the StartupUri from the App.xaml so that you don't get two main windows when the application starts.