-
Notifications
You must be signed in to change notification settings - Fork 22
Usage
After you created your new application as described in Preparation, here are the first steps to get your app running with TinyLittleMvvm:
Install-Package TinyLittleMvvm
Add a folder ViewModels
to your project. Add a class in this folder named MainViewModel
, derive it from PropertyChangedBase
.
public class MainViewModel : PropertyChangedBase {
}
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>
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.