Hello Caliburn – beginners guide to an amazing framework (1)

I knew about Caliburn for some time but never really tried it until I've found a very simple solution to a problem that appeared complicated. After struggling a bit and asking some newbie-stupid questions on twitter I've decided to get to know the framework from the beginning. And of course I was trying to understand a big sample before reading any documentation so everything seemed very hard and complicated. Since I could not find any tutorial with a legendary 'hello caliburn' application I've decided to write one - for me to remember basics and maybe for someone else to get them too.

Caliburn gives a WPF developer a lot of helpers but for me the most important was to make me use presentation patterns properly, make my code neat, well organized, easy to read. I also hope to learn some about testability goods that comes with using Caliburn. This post is based on an application given as a sample with the release and shows how to build a very first Cliburn application.

CaliburnApplication

To make things easiest possible I've decided not to try manual configuration and use a CaliburnApplication class. It configured everything I needed. Now my application is:

using Caliburn.PresentationFramework.ApplicationModel;
namespace HelloCaliburn
{
public partial class App : CaliburnApplication{}
}
<ApplicationModel:CaliburnApplication x:Class="HelloCaliburn.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ApplicationModel="clr-namespace:
Caliburn.PresentationFramework.ApplicationModel;
assembly=Caliburn.PresentationFramework"
>
</ApplicationModel:CaliburnApplication>

View

<Window x:Class="HelloCaliburn.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Hello" Height="300" Width="300">
<Label Margin="50" Content="Hello Caliburn! :-)"/>
</Window>

Presenter

namespace HelloCaliburn.Presenters
{
public class MainPresenter : IMainPresenter {}
public interface IMainPresenter {}
}

The only important thing to remember is naming conventions. Views should be named: My.Namespace.Views.NameView and presenters My.Namespace.Presenters.NamePresenter
It helps to have the same folders names (another benefit of Caliburn - I've learned that naming and putting things in common places is good and important)

image

Final application

One small method in the application class:

public partial class App : CaliburnApplication
{
protected override object CreateRootModel()
{
return Container.GetInstance<IMainPresenter>();
}
}
One attribute to register my presenter:
[PerRequest( typeof( IMainPresenter ) )]
public class MainPresenter : IMainPresenter
{
}
Hit F5 and done :-)
image 
Happy caliburning ;-) Code here,
Monika
 

No Comments