Project Setup

There are a couple of simple steps you must follow when getting started with Caliburn.
  1. If you have not already obtained and built the code, please go ahead and do this now.
  2. Create a new WPF/SL application or open an existing application.
  3. Add references to Caliburn.Core, Caliburn.PresenationFramework and Microsoft.Practices.ServiceLocation.
  4. Open the App.xaml.cs file in your project.
  5. Add the following using (vb: import) statements to this class: Caliburn.Core, Caliburn.PresenationFramework
  6. For WPF, add the following code to the constructor. For Silverlight add the following code to the beginning of the Application_Startup method:

CaliburnFramework
    .ConfigureCore()
    .WithPresentationFramework()
    .Start();

As you can imagine, this simply configures the core framework and the various features for use in your application. That's all you need to do to get started! As an alternative, you can inherit your Application class from CaliburnApplication and this configuration will happen automatically. There are other features gained from using the CaliburnApplication class as well (discussed elsewhere).

Note: To more easily use Caliburn's attached properties, you should add the following XML Namespace declaration to your XAML files: xmlns:cal="http://www.caliburnproject.org"

More advanced users may wish to customize Caliburn's configuration. There are a variety of ways to do this. Each "With" method returns a class with specific methods related to configuring that piece of the framework. Essentially, Caliburn is a collection of UI services that work together to solve complex problems. Any of its services can be switched out with custom implementations, but this should be rarely necessary, if ever. This ability is powered by Caliburn's deep usage of dependency injection through an extensible mechanism for dependency injection containers. Caliburn provides it's own simple implementation of a DI container, which it uses by default. However, it can be replaced easily by implementing the IServiceLocator interface (you should also implement IConfigurator or provide a delegate which can configure the container with the provided components). Caliburn provides implementations for Windsor(Caliburn.Windsor), StructureMap(Caliburn.StructureMap), Spring.NET(Caliburn.Spring), Unity(Caliburn.Unity), Ninject(Caliburn.Ninject), MEF(Caliburn.MEF) and Autofac(Caliburn.Autofac) out of the box. Below is an example of using Windsor with Caliburn as well as some custom configuration:

public partial class App : Application
{
    public App()
    {
        //Note: Using an external container via adapter.  The usage pattern is the same for all supported containers.
        var container = new WindsorContainer();
        var adapter = new WindsorAdapter(container);
 
        CaliburnFramework
            .ConfigureCore(adapter)
            .WithPresentationFramework()
            .Start();
 
        //Note: Retrieve one of Caliburn's services.
        var controller = container.Resolve<IRoutedMessageController>();
 
        //Note: Customize the default behavior of button elements.
        controller.SetupDefaults(
            new GenericInteractionDefaults<Button>(
                "MouseEnter",
                (b, v) => b.DataContext = v,
                b => b.DataContext
                )
            );
    }
}

Last edited Dec 27, 2009 at 9:45 PM by EisenbergEffect, version 13