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

Best way to implement "Statically-typed view model" approach? #589

Closed
YkTru opened this issue Dec 6, 2023 · 5 comments
Closed

Best way to implement "Statically-typed view model" approach? #589

YkTru opened this issue Dec 6, 2023 · 5 comments

Comments

@YkTru
Copy link

YkTru commented Dec 6, 2023

I'm having trouble understanding how to implement the statically-typed view model approach. (everything is working fine with the bindings approach)

I attempted to use the guidance from Elmish.WPF on GitHub, but despite spending a lot of time on it, I find the documentation either unclear or possibly outdated. Is there a complete and current sample that demonstrates the best way to do this?

I've been working on this implementation, but regardless of my efforts, the 'HelloViewModel' does not appear in Intellisense. Here's my attempt: https://github.com/YkTru/ElmishWPF_StaticallyTypedViewModel.

Any assistance would be greatly appreciated. Thank you.

@YkTru YkTru changed the title Best way to do "Statically-typed view model" approach Best way to implement "Statically-typed view model" approach Dec 6, 2023
@YkTru YkTru changed the title Best way to implement "Statically-typed view model" approach Best way to implement "Statically-typed view model" approach? Dec 6, 2023
@YkTru
Copy link
Author

YkTru commented Dec 7, 2023

@TysonMN @marner2

I'm sorry to bother you, but am I doing anything wrong? Thank you.

@marner2
Copy link
Collaborator

marner2 commented Dec 8, 2023

Ahh, I see what the problem is. Yes, your View Model cannot be inside a module, as XAML doesn't support nested types (F# modules are implemented as types in .NET). This slightly complicates your simple example, as you'll have to split things up into several modules.

Take your view model and put it outside and after the zApp module, then put the main function inside another module after the view model. You'll also need to move the Elmish.WPF open under the namespace.

I'll work on making the documentation clearer with an explicit section in the docs around this feature.

The example of this is in SubModelStatic.Core. It's a bit more involved as I wanted to illustrate how you get nested auto-completions in the wpf xaml designer if you use this method.

Let me know if you have any more questions or suggestions!

@YkTru YkTru closed this as completed Dec 10, 2023
@YkTru
Copy link
Author

YkTru commented Dec 10, 2023

It works, thanks a lot!

  1. I've created a new sample with more relevant State/Msg; do you want me to share it so you can review it, and then maybe add it to the Elmish.WPF samples?

I must mention, as a newcomer transitioning directly from C#+MVVM, such a sample would have saved me a great deal of time and effort. (I guess from the documentation any F# programmer would have figured it out rapidly, but for anyone in a learning process I think it might no be as evident)


  1. Do you personally recommend/prefer the bindings approach or the statically-typed VM one? I obviously lean towards the bindings approach for readability, but I assume that typed XAML bindings are way more advantageous than those based on strings?

I'm asking since in the samples, clearly the bindings approach is preferred, so does it have any advantages versus the other one other than readability and a more "functionnal" style?

Thank you again

@LyndonGingerich
Copy link
Contributor

@YkTru

If you have a sample to suggest already made, by all means share it. Even if we don't use it directly, it could inspire ideas.

The "view model class" approach is relatively new, which is why the "binding list" approach has many more samples. If you use view model classes, you will be able to navigate from XAML binding usages to their definitions in Rider and Visual Studio. Rider will also check XAML when you search for usages. I don't think that the "binding list" approach has any particular advantages, but we will keep it around to avoid breaking existing code.

@TysonMN
Copy link
Member

TysonMN commented Dec 16, 2023

Do you personally recommend/prefer the bindings approach or the statically-typed VM one? I obviously lean towards the bindings approach for readability, but I assume that typed XAML bindings are way more advantageous than those based on strings?

(We having been calling them dynamic bindings and static bindings.)

I prefer dynamic bindings, but I stopped using Elmish.WPF (due to job change) before static bindings were created.

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

4 participants