Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LyndonGingerich opened this issue Jun 12, 2023 · 3 comments

Comments

@LyndonGingerich
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Member

TysonMN commented Jun 13, 2023

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

@marner2
Copy link
Collaborator

marner2 commented Nov 7, 2023

This has been fixed.

@marner2 marner2 closed this as completed Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants