PaulWebbster
PaulWebbster

Reputation: 1540

Caliburn Micro View First Bootstrapper OnStartup for WPF application

First of all this is my first contact with Caliburn.Micro, C# and WPF. I have gone through the Calibur.Micro tutorial and stopped in the moment of "All about actions" and First View subsection. Author wrote the solution for Silverlight application as follow:

public class MefBootstrapper : BootstrapperBase
{
    //same as before

    protected override void OnStartup(object sender, StartupEventArgs e)
    {
        Application.RootVisual = new ShellView();
    }

    //same as before
 } 

So this is solution how to say bootstrapper which view use as base to show. About WPF I get only enigmatic information:

In this scenario, we simply override OnStartup, instantiate the view ourselves and set it as the RootVisual (or call Show in the case of WPF).

So the Silverlight example is very clear for me, we just manually instantiate the proper View to property Application.RootVisual. But is for me totally unclear what is the Show method, which member it is. How to call it.

Thanks for help!

Upvotes: 1

Views: 1662

Answers (1)

Mat J
Mat J

Reputation: 5632

Caliburn.Micro provides a BootstrapperBase class from which you can inherit your own bootstrapper class. It has a virtual method OnStartup which you can override to do the initialization of your shellview. It also provides a utility method DisplayRootViewFor which can be used for displaying the related view for a specified viewmodel type.

So a simple implementation would look like this,

protected override void OnStartup(object sender, StartupEventArgs e)
{
    DisplayRootViewFor<TShellViewModel>();
}

where TShellViewModel is the type of your Shell ViewModel. Framework will resolve the view using convention and does the necessary groundwork to display the same. This link will provide a broader picture for a MEF based IOC supported bootstrapper implementation for WPF.

Upvotes: 2

Related Questions