0

I am creating a large WPF desktop application using Prism 7 and I need to create several VSTO add-ins for Word and Excel that are smaller parts of the larger whole. I want to use Prism 7 to inject my already created views and viewmodels into a xaml Window that gets shown when a button on the ribbon is clicked.

I don't know where to initialize the bootstrapper though as I am unfamiliar with VSTO add-ins.

I have already created a bootstrapper that configures the module catalog with the correct modules that contain the necessary views. Bootstrapper is as follows.

public sealed class Bootstrapper : PrismApplication
{
    protected override Window CreateShell()
    {
        return Container.Resolve<MainWindow>(); //Where MainWindow is the window that should be shown when the button is clicked.
    }

    protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
    {
        base.ConfigureModuleCatalog(moduleCatalog);

        moduleCatalog.AddModule(typeof(MyModule)); //Where MyModule is the Prism module for the project that contains the views I want to inject
    }
}

When I initialize the bootstrapper from the ThisAddIn.cs file as shown below, the bootstrapper properly creates itself and configures the module catalog. Afterwards the container is able to resolve the RegionManager, but it also automatically displays the MainWindow to the user.

public partial class ThisAddIn
{
    private Bootstrapper _bootstrapper;

    private void ThisAddIn_Startup(object sender, EventArgs e)
    {
        _bootstrapper = new Bootstrapper(); //MainWindow is displayed after everything runs
    }
}

If I leave the MainWindow open and click the button which should inject the views into the MainWindow the views are properly injected. However, I obviously don't want to automatically display a blank window every time a user opens up a Word document. Is there a way to stop the Bootstrapper from showing the MainWindow at this point or is there a better way altogether to go about this?

Chris
  • 3,400
  • 1
  • 27
  • 41
jwlford
  • 58
  • 8
  • Is this behavior different than what you would expect with a non-VSTO application? – Chris Jan 11 '19 at 17:45
  • Not really no. I just need to stop the window from automatically opening when the VSTO application is run and only open up when a button on a custom ribbon tab is clicked. I tried to instantiate the bootstrapper when the button is clicked but it doesn't fully load by the time I need to grab the RegionManager to inject a view into the window. – jwlford Jan 11 '19 at 21:19

0 Answers0