Need help with Elmish.WPF?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

300 Stars 54 Forks Other 775 Commits 43 Opened issues


Static WPF views for elmish programs.

Services available


Need anything else?

Contributors list

WPF done the Elmish Way

NuGet version NuGet downloads Build status

The good parts of MVVM (the data bindings) with the simplicity and robustness of an MVU architecture for the rest of your app. Never write a ViewModel class again!

Elevator pitch

Elmish.WPF is a production-ready library that allows you to write WPF apps with the robust, simple, well-known, and battle-tested MVU architecture, while still allowing you to use all your XAML knowledge and tooling to create UIs.

Some benefits of MVU you’ll get with Elmish.WPF include:

  • Simple-to-understand, unidirectional data flow
  • Single source of truth for all the state in your app
  • Simple async/IO
  • Immutable data
  • Pure functions
  • Great testability
  • Simple optimization
  • 78% more rockets 🚀

Even with static views, your central model/update code can follow an idiomatic Elmish/MVU architecture. You could, if you wanted, use the same model/update code to implement an app using a dynamic UI library such as Fabulous or Fable.React, by just rewriting the “U” part of MVU.

Static XAML views is a feature, not a limitation. See the FAQ for several unique benefits to this approach!

Elmish.WPF uses Elmish, an F# implementation of the MVU message loop.

Big thanks to @MrMattSim for the wonderful logo!


JetBrains logo

Thanks to JetBrains for sponsoring Elmish.WPF with OSS licenses!

Recommended resources

Getting started with Elmish.WPF

See the SingleCounter sample for a very simple app. The central points are (assuming up-to-date VS2019):

  1. Create an F# Class Library. If targeting .NET 5 or .NET Core, the project file should look like this:

   <targetframework>net5.0-windows</targetframework>  <!-- Or another target framework -->

 <!-- other stuff -->

If targeting .NET Framework (4.6.1 or later), replace the first line with

  1. Add NuGet reference to package

  2. Define the model that describes your app’s state and a function that initializes it:

   type Model =
     { Count: int
       StepSize: int }

let init () = { Count = 0 StepSize = 1 }

  1. Define the various messages that can change your model:
   type Msg =
     | Increment
     | Decrement
     | SetStepSize of int
  1. Define an
    function that takes a message and a model and returns an updated model:
   let update msg m =
     match msg with
     | Increment -> { m with Count = m.Count + m.StepSize }
     | Decrement -> { m with Count = m.Count - m.StepSize }
     | SetStepSize x -> { m with StepSize = x }
  1. Define the “view” function using the
    module. This is the central public API of Elmish.WPF.

Normally in Elm/Elmish this function is called

and would take a model and a dispatch function (to dispatch new messages to the update loop) and return the UI (e.g. a HTML DOM to be rendered), but in Elmish.WPF this function is in general only run once and simply sets up bindings that XAML-defined views can use. Therefore, let’s call it
instead of
   open Elmish.WPF

let bindings () = [ "CounterValue" |> Binding.oneWay (fun m -> m.Count) "Increment" |> Binding.cmd (fun m -> Increment) "Decrement" |> Binding.cmd (fun m -> Decrement) "StepSize" |> Binding.twoWay( (fun m -> float m.StepSize), (fun newVal m -> int newVal |> SetStepSize)) ]

The strings identify the binding names to be used in the XAML views. The Binding module has many functions to create various types of bindings.

  1. Create a function that accepts the app’s main window (to be created) and configures and starts the Elmish loop for the window with your
   open Elmish.WPF

let main window = Program.mkSimpleWpf init update bindings |> Program.runElmishLoop window

In the code above,

will set the window’s
to the specified bindings and start the Elmish dispatch loop for the window.
  1. Create a WPF app project (using the Visual Studio template called
    WPF App (.NET)
    ). This will be your entry point and contain the XAML views. Add a reference to the F# project, and make the following changes in the
  • Currently, the core Elmish logs are only output to the console. If you want a console window for displaying Elmish logs, change
    and add
  • If the project file starts with the now legacy
    , change it to 
  • Change the target framework to match the one used in the F# project (e.g.

Make the following changes to

to initialize Elmish when the app starts:
   public partial class App : Application
     public App()
       this.Activated += StartElmish;

 private void StartElmish(object sender, EventArgs e)
   this.Activated -= StartElmish;


  1. Define your views and bindings in XAML:
  1. Profit! :)

Further resources:

  • The Elmish.WPF tutorial provides information on general MVU/Elmish concepts and how they apply to Elmish.WPF, as well as the various Elmish.WPF bindings.
  • The samples are complete, working mini-apps demonstrating selected aspects of Elmish.WPF.
  • If you'd like to contribute, please read and follow the Contributor guidelines.


Static views in MVU? Isn’t that just a half-baked solution that only exists due to a lack of better alternatives?

Not at all! 🙂

It’s true that static views aren’t as composable as dynamic views. It’s also true that at the time of writing, there are no solid, production-ready dynamic UI libraries for WPF (though there are no lack of half-finished attempts or proof-of-concepts: Elmish.WPF.Dynamic, Fabulous.WPF, Skylight, Uil). Heck, it’s even true that Elmish.WPF was originally created with static views due to the difficulty of creating a dynamic UI library, as described in issue #1.

However, Elmish.WPF’s static-view-based solution has several unique benefits:

  • You can use your existing XAML and MVVM knowledge (that is, the best part of MVVM – the UI bindings – without having to deal with
    s, state synchronization,
    , etc.)
  • Huge mindshare – there are tons of relevant XAML and MVVM resources on the net which can help with the UI and data binding part if you get stuck
  • Automatic support for all 3rd party WPF UI libraries like MaterialDesignInXamlToolkit, since it just uses XAML and bindings (support for 3rd party libraries is commonly a major pain point for dynamic UI solutions)
  • You can use the XAML designer (including design-time data binding)
  • Automatically puts all the power of WPF at your fingertips, whereas dynamic UI solutions have inherent limitations that are not easy to work around

In short, for WPF apps, a solution based on static XAML views is currently the way to go.

Do I have to use the project structure outlined above?

Not at all. The above example, as well as the samples, keep all non-UI code in a single project for simplicity, and all the XAML in a C# project for better tooling.

An alternative with a clearer separation of UI and core logic can be implemented by splitting the F# project into two projects:

  • A core library containing the model definitions and
    • This library can include a reference to Elmish (e.g. for the
      module helpers), but not to Elmish.WPF, which depends on WPF and has a UI-centered API (specifying bindings). This will ensure your core logic (such as the
      function) is free from any UI concerns, and allow you to re-use the core library should you want to port your app to another Elmish-based solution (e.g. Fable.React).
  • An Elmish.WPF project that contains the
    ) function and the call to
    • This project would reference the core library and

Another alternative is to turn the sample code on its head and have the F# project be a console app containing your entry point (with a call to

) and referencing the C#/XAML project (instead of the other way around, as demonstrated above).

In general, you have a large amount of freedom in how you structure your solution and what kind of entry point you use.

How can I test commands? What is the CmdMsg pattern?

Since the commands (

) returned by
are lists of functions, they are not particularly testable. A general pattern to get around this is to replace the commands with pure data that are transformed to the actual commands elsewhere:
  • Create a
    union type with cases for each command you want to execute in the app.
  • Make
    model * CmdMsg list
    instead of
    model * Cmd
    . Since
    now return data, they are much easier to test.
  • Create a trivial/too-boring-to-test
    function that transforms a
    to the corresponding
  • Finally, create “normal” versions of
    that you can use when creating
    . Elmish.WPF provides
    that does this for you (but there’s no magic going on – it’s really easy to do yourself).

The FileDialogsCmdMsg sample demonstrates this approach. For more information, see the Fabulous documentation. For reference, here is the discussion that led to this pattern.

Can I use design-time view models?

Yes. Assuming you have a C# XAML and entry point project referencing the F# project, simply use

(e.g. in the F# project) to create a view model instance that your XAML can use at design-time:
module MyAssembly.DesignViewModels
let myVm = ViewModel.designInstance myModel myBindings

Then use the following attributes wherever you need a design-time VM:

When targeting legacy .NET Framework, “Project code” must be enabled in the XAML designer for this to work.

.NET Core 3 workaround

When targeting .NET Core 3, a bug in the XAML designer causes design-time data to not be displayed through

bindings. See this issue for details. One workaround is to add a
binding alongside your normal
binding. Another workaround is to change



is the type of the parent object that contains
(or a more distant ancestor, though there are issues with using
as the type).

Can I open new windows/dialogs?

Sure! Just use

. It works like
, but has a
wrapper around the returned model to control whether the window is closed, hidden, or visible. You can use both modal and non-modal windows/dialogs, and everything is a part of the Elmish core loop. Check out the NewWindow sample.

Note that if you use

startup, you may want to set
if that’s the desired behavior.

Can I bind to events and use behaviors?

Sure! Check out the EventBindingsAndBehaviors sample. Note that you have to install the NuGet package


How can I control logging?

Elmish.WPF uses

. To see Elmish.WPF output in your favorite logging framework, use
to pass an
WpfProgram.mkSimple init update bindings
|> WpfProgram.withLogger yourLoggerFactory
|> WpfProgram.runWindow window

For example, in Serilog, you need to install Serilog.Extensions.Logging and instantiate

. The samples demonstrate this.

Elmish.WPF logs to these categories:

  • Elmish.WPF.Update
    : Logs exceptions (Error level) and messages/models (Trace/Verbose level) during
  • Elmish.WPF.Bindings
    : Logs events related to bindings. Some logging is done at the Error level (e.g. developer errors such as duplicated binding names, using non-existent bindings in XAML, etc.), but otherwise it’s generally just Trace/Verbose for when you really want to see everything that’s happening (triggering
    , WPF getting/setting bindings, etc.)
  • Elmish.WPF.Performance
    : Logs the performance of the functions you pass when creating bindings (
    , etc.) at the Trace/Verbose level. Use
    to set the minimum duration to log.

The specific method of controlling what Elmish.WPF logs depends on your logging framework. For Serilog you can use

to specify the minimum log level per category, like this:
  .MinimumLevel.Override("Elmish.WPF.Bindings", LogEventLevel.Verbose)

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.