View Model Communication/Messaging - EASY WPF (.NET 5)

preview_player
Показать описание
Learn how to send messages and communicate between multiple view models. This concept is crucial for implementing other WPF infrastructure, such as navigation or state management. View model communication involves creating a "pub/sub" mediator object that will take in messages and send them to subscribing view models. Other concepts covered include events and disposing event handlers.

TIMESTAMPS:
0:00 - Introduction
0:21 - Demo Introduction
1:22 - Unrecommended Solution
2:13 - Recommended Solution (Pub/Sub, Mediator)
2:59 - Implementation
6:26 - Testing
6:40 - Disposing Store Subscriptions
8:00 - Conclusion

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

your tutorials are actually the best I have found on this platform in terms of style and content, thanks for that

marcb
Автор

Excellently stated, with a reference to a challenge many experience within WPF development.

anselm
Автор

Great, this is what I've been waiting for! Thank you!

veroqtno
Автор

A diagram showing the connections and communication pathways would be really cool. May need to look at the code and try and come up with one.

ElCidPhysics
Автор

That was helpfull! Thanks for the tip about disposing

bartomiejciurla
Автор

Thank you for the great content!
I have a question: what's wrong with having a main parent view model shared between its children view models? OK it is coupled, but only to the main view model which would act as a shared data source. Isn't it cleaner instead of having custom events for everything? It is not a criticism, but a genuine question. Thank you!

piotrgoacki
Автор

Thank you for your videos @SingletonSean, I come from a JS frontend background and I am struggling to understand WPF. Most of the videos I see here are already outdated and doesn't click with me. Your videos are very clear, I hope you would be doing more of state management videos and thread/tasks/workers as well.

geocine
Автор

Great content as always, but I want to ask you, when the application will call Dispose() on the ProductionListingViewModel ?

jozefvendel
Автор

Question, say that you allow a product to have an image as well which you would select via openfilefdialog and show it in both views. Where you the appropriate place to call fileopenfdialog? In the viewmodel or in the code behind? It's in the code behind how do I communicate from the codebehind to the view model?

СашаДискотека-лй
Автор

very awesome tutorial
many many thanks
but why do you pass product class to store and not passing the product viewmodel it self?
can we make the productstore as static class??

solvedplus
Автор

Thank you. Very informative. Stil w8 you're Mvvm navigation tutorial without "main" navigation menu.

TheMilliardo
Автор

Awesomee tutorial bro!! It is Awesomeee

gabrieldesouza
Автор

Hello Sean,
This doesn't seem to work as well as I thought it would as it seems that you have to pass into the constructor viewmodel, an instance of the viewmodel from which you would like to get information. What I've seen is that if I do this then I can't use the viewmodel within my view as it reports that the viewmodel must be parameterless. So am I missing something? or what am I doing wrong?

robertthurman
Автор

I have two views (pages) that need to communicate between each other. View1 will fire UpdatedEvent on navigating to View2, and View2 will fire UpdatedEvent on navigating back to View1.

Problem:
I use DI and ViewModel2 that is connected to View2 is initialized after View1 called UpdatedEvent.
So on first navigation, ViewModel2 doesn't fire event, therefore property is not changed.

How can I fix this problem?

AdisonCavani
Автор

Anybody has any idea why we want to separate commands in another folder instead of just putting it in the ViewModel. By doing so we need to add a reference of ViewModel in each command, is it coupling the code?

samjiang
Автор

Heyy one question, using this settup how would yu communicate with a entity framework ? Happy new year !!

gabrieldesouza
Автор

Great video as usual! What are your thoughts on incorporating the Windows API in 2021 and is it still needed? .NET versions prior and up to 5.0 have wrapped most functions but there are still some that P/Invoke is needed for. Perhaps a video on this?

chisoxnation
Автор

Great video but I got lost on the ProductListingViewModel... The whole memory leak thing just confuses me. :( other than that great tutorial.

lottexy
Автор

I have one question! What if we want to edit or delete products. As in this example you displayed two ViewModel in one view. Can you please guide about how to create for views individually for both ViewModels.?

purswani
Автор

Around 5:27 a message popsup talking about WPF bindings must be on INotifyPropertyChanged objects, otherwise there are potential memory leaks. Can you create a video or point to a video that goes more in-depth?

Perhaps start out with code not optimized and then convert to the optimized way to avoid the leaks.

GrullonMiguel