First light is the term used for the first time that an observation is made through a new telescope (or other astronomical instrument). Lets get our application up and running.


There are two different ways that WPF applications can start up.

The most common approach is to specify the initial window using StartupUri in App.xaml. Unfortunately, this doesn’t play well with the MVVM architecture we’re using.

The alternative approach is to use a traditional Main() entry point that sets everything up for the application to run.

In a new Program.cs file, write a method to create our initial application model:

private static WordTutorApplication CreateApplicationModel()
    var screen = new AddVocabularyWordScreen()
        .WithPhrase("This is a demo phrase")

    var application = new WordTutorApplication(screen);
    return application;

We create the screen with the fields already populated so that we can verify our data-binding is working. As we progress the application, we’ll remove those.

Next, we need a method to set up our Redux store, containing both our reducer and the initial application state:

private static IReduxStore<WordTutorApplication> CreateStore(WordTutorApplication application)
    var screenReducer = new ScreenReducer();
    var appReducer = new WordTutorAppicationReducer(screenReducer);
    var store = new ReduxStore<WordTutorApplication>(
        appReducer, application);
    return new LoggingReduxStore<WordTutorApplication>(store);

The LoggingReduxStore is a debugging tool that wraps the actual store, writing details of each dispatched message using Debug.WriteLine() before passing them through.

And finally we can create the entry point:

static void Main()
    var app = new App();

    var application = CreateApplicationModel();
    var store = CreateStore(application);
    var model = new AddVocabularyWordViewModel(store);
    var view = new AddVocabularyWordView
        DataContext = model

    var mainWindow = new MainWindow();
    mainWindow.Shell.Content = view;


While this looks a bit verbose right now, things will become a lot simpler when we introduce more support infrastructure and use of a dependency injection tool.

Prior post in this series:
Add Word View
Next post in this series:
Revisiting ViewModelBase


blog comments powered by Disqus