There are a couple of simple steps you must follow when getting started with Caliburn.
- If you have not already obtained and built the code, please go ahead and do this now.
- Create a new WPF/SL application or open an existing application.
- Add references to Caliburn.Core, Caliburn.PresenationFramework and Microsoft.Practices.ServiceLocation.
- Open the App.xaml.cs file in your project.
- Add the following using (vb: import) statements to this class: Caliburn.Core, Caliburn.PresenationFramework
- For WPF, add the following code to the constructor. For Silverlight add the following code to the beginning of the Application_Startup method:
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
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.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
//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);
//Note: Retrieve one of Caliburn's services.
var controller = container.Resolve<IRoutedMessageController>();
//Note: Customize the default behavior of button elements.
(b, v) => b.DataContext = v,
b => b.DataContext