Simplifying View Models (Best Practices) - EASY WPF (.NET 5)

preview_player
Показать описание
Learn how to simplify view models. A view model is a "model for the view", but sometimes we make our view models complex, gigantic, and inflexible. Simplifying view models will help our applications stay flexible and maintainable.

TIMESTAMPS:
0:00 - Introduction
0:25 - Issues
1:49 - Demo Introduction
3:37 - Class Commands
9:33 - Command Flexibility
14:23 - Testing
14:59 - Summary
15:35 - Potential Drawbacks
16:40 - Conclusion

OTHER LINKS:
Рекомендации по теме
Комментарии
Автор

Great tutorial! I used to have everything in my ViewModel, which is quite large for some.
Good time for me to implement what I have learned here.
Thanks!

michaelwong
Автор

Hi Sean, thank you for sharing your knowlege. I'm a newB but I love your way of teaching and your architecture seem clear to me. Keep up please. Respect!

jean-francoispedneault
Автор

Been wondering about better options than instantiating commands in the VM if flexibility is needed so this is great! Thank you, as always.

pleasecheckmyid
Автор

I always like to see new ways to handle problems. Thank you for your time and work to on your awesome videos. 😉

But in most cases I will stay with command handling in the vm.
If the vm is getting to big and complex. I would try to split it up in smaller pieces.

MrJPhardy
Автор

Hi Sean, i've got a question please,
why dont you just pass into the vm's constructor the commands itself and instead you wrap it with delegate?

Автор

Thanks for the tutorial, it's really helpful and I like the video's structure a lot, keep it up! :)

HadiLePanda
Автор

You're a wizard. I'm a huge fan

Robin-uuwx
Автор

Quiero programar con esa fluidez T_T

Explicaste de manera eficiente sólida
Agradecido con tu contenido. ¿Recomiendas algún libro para profundizar los temas que trataste?
Se me hace un lío aplicar todos los conceptos. Soy nuevo en el tema

jacobdasilva
Автор

Awesome stuff! I wish I had that earlier and I'm glad I have it now.

ak-dyty
Автор

I think extracting command call back methods might be good for low or mid-level apps but when the apps grow big enough this approach might just add more complexity to the project and make it harder to maintain.

cyrildouglas
Автор

simple? The more mvvm videos i watch the more i think I should go back to winforms. I started to love working with wpf until I started trying to go the mvvm route, so much more code needed, a small project quickly become larger.

Great videos and content. Any chance of doing windows forms videos?

hawkeyezar
Автор

How the F*ck I have not seen this video, It took me too long to understand WPF and this right here is probably the best Layman explanation I've seen. Only masters can explain to a toddler.
I am so f*cking upset for wasting my time learning from other mofos. Sh*t I could've save a lot of time. Thank you Very much.

exogendesign
Автор

Hello there, how is your progress looking into ReactiveUI?

Tof__
Автор

How add CreateCommand to dependency injection?

dzaro
Автор

And now we have passed the point where the abstractions are not adding anything. You are just smearing the business logic allover the code base. (see fizzbuzz corporate)

The view model is there to present the view with a "view" of the model that is can "bind to".

Buy and calculate price is part of the model and as there should be a model with a proper API that is view agnostic and do not concern itself with what view that is "binding" to it.

One model -> Multiple View Models (One for WPF and one REST API) -> multiple views and the businesses logic SHALL be in the model and not smeared all over the different view models.

marcbotnope
Автор

When I did this in my work, a colleague that is our boss told me that he couldn't find any information anywhere about this pattern and made me put the commands back in the viewmodel. He even treat me like a stupid for doing this. This guy is an arrogant because he programs since he is 8 years old and in many languages and likes to humiliate persons. He said to me commands have to be inside the viewmodel.

NoAlias
Автор

I was totally skeptical of this approach until I actually tried it, and now I am a huge fan. I felt like the file clutter would be annoying, but I've found that it is actually easier to maintain, test, debug, and to replace components that need updated functionality without being forced to replace existing code. I've already started converting one of my main projects and will consider this my go-to from now on.

One note is that you can have the command requery the CanExecute method by using CommandManager .RequerySuggested

public event EventHandler CanExecuteChanged
{
add { += value; }
remove { -= value; }
}

It seems to work consistently in most situations except for CollectionChanged, in my experience.

joshman
Автор

Still way too complicated.
You want to create 100 classes of Commands if your ViewModel has 100 functions?
That sounds even more scary to maintain than just write the logic into the view model.

GnomeEU