elmish / Elmish.WPF

Static WPF views for elmish programs
Other
421 stars 68 forks source link

Documentation doesn't specify how to define Program.main using typed view model classes #571

Closed LyndonGingerich closed 8 months ago

LyndonGingerich commented 1 year ago

High-level description

From README.md:

  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 init, update and bindings:

open Elmish.WPF

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

In the code above, Program.runElmishLoop will set the window’s DataContext to the specified bindings and start the Elmish dispatch loop for the window.

As far as I can tell, Program.mkSimpleWpf no longer exists.

Here's my current best try:

module Program =
    let main window =
        WpfProgram.mkSimpleT Model.init Model.update ModelViewModel |> WpfProgram.runWindow window

This throws the following exception:

System.InvalidOperationException: Application is already running the Dispatcher.
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at Elmish.WPF.WpfProgram.runWindow[a,b,c](Window window, WpfProgram`3 program) in D:\a\Elmish.WPF\Elmish.WPF\src\Elmish.WPF\WpfProgram.fs:line 248

I'll keep troubleshooting, but my main point is that the right way isn't obvious, at least to me.

Additional Information Elmish.WPF version: 4.0.0-beta-50 Target framework version: net7.0-windows

LyndonGingerich commented 1 year ago

I didn't think to check the samples. Here's working code:

module Program =
    let main (window: System.Windows.Window) =
        WpfProgram.mkSimpleT Model.init Model.update ModelViewModel
        |> WpfProgram.startElmishLoop window

Could we still document this, though?

TysonMN commented 1 year ago

Yes, of course. Want to write the document and submit a PR?

marner2 commented 8 months ago

This has been fixed.