Skip to content
Thomas Freudenberg edited this page Sep 5, 2018 · 2 revisions

After you created your new application as described in Preparation, here are the first steps to get your app running with TinyLittleMvvm:

1 Add TinyLittleMvvm NuGet package

Install-Package TinyLittleMvvm

2 Create your first view model

Add a folder ViewModels to your project. Add a class in this folder named MainViewModel, derive it from PropertyChangedBase.

public class MainViewModel : PropertyChangedBase {
}

3 Create the corresponding view

Add a folder Views to your project. Add a WPF Window MainView to this folder, and immediately delete MainView.xaml.cs afterwards.

Since we're using MahApps.Metro, change the base class to MetroWindow. Your window's XAML should now look like this:

<Controls:MetroWindow x:Class="WpfApplication1.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
        Title="MainView" Height="300" Width="300">
    <Grid>
        
    </Grid>
</Controls:MetroWindow>

4 Add the bootstrapper

Add a class AppBootstrapper inheriting BootstrapperBase<MainViewModel> and register your view and your view model to the Autofac container. Just override the ConfigureContainer() method like this:

protected override void ConfigureContainer(ContainerBuilder builder) {
    base.ConfigureContainer(builder);

    builder.RegisterType<MainViewModel>();
    builder.RegisterType<MainView>();
}

And finally add your AppBootstrapper to your application resources in App.xaml as follows:

<ResourceDictionary>
    <WpfApplication1:AppBootstrapper x:Key="bootstrapper" />
</ResourceDictionary>

Now you can start your application, your MainView will be displayed with it's DataContext set to MainViewModel instance.