WPF Switching Views With Navigation Using MVVM And Dependency Injection

  Рет қаралды 57,472

Payload

Payload

Күн бұрын

WPF Switching Views With Navigation Using MVVM And Dependency Injection this tutorial will show you how to switch views in wpf using MVVM and dependency injection using C# the programming language and WPF the programming UI framwork in order to navigate through multiple views you can use this with multiple windows as well this is a tutorial and a guide on how to create a professional wpf application using C# and how to navigate through multiple views in WPF.
Patreon: / payloads
Discord: / discord

Пікірлер: 120
@_buffer
@_buffer Жыл бұрын
Patreon: www.patreon.com/payloads Discord: discord.gg/kNFPKhvnYz
@cebulaczerwona3425
@cebulaczerwona3425 Жыл бұрын
I beg you for explanation video for idiots (like me) what is what, for example what we are exactly doing in App.xaml, what is IServiceCollection etc. ok, so I watched to the end, and I'm completely lost ): . I mean I understand base functionality but func? NavigationService? idk. And yes i know documentation i looked at it and 0-0. I will Love explenation viedo on this exact project.
@niangel2704
@niangel2704 9 ай бұрын
@cebulaczerwona3425 This is the one missing from all over internet! No one explains what he does and why he does it!! They just keep typing and typing and typing... What's the point of spending hours typing a code that could be presented as a source code!! Either they do that to earn money or they do NOT know how to teach!! If you want to teach something to someone you need to go down to the level of the learner and realize the questions that he would be asking if you were face to face with him!! Unfortunately there are no good teachers. They just typing and typing... I have subscribed here but I am disappointed... And what is the point of narrating something like you are in a hurry to go to the loo!! To teach someone you need to be not only a good programmer but also a good teacher!! Once again disappointed!!
@_buffer
@_buffer 9 ай бұрын
I understand where you're coming from, and the issue is that explaining that would require it's own video. A good idea would look at the implementation in the video and try to understand what's going on combined with MSDN for instance. Or join the Discord server and ask more direct questions there. Appreciate the feedback! @@niangel2704
@SHUJA837
@SHUJA837 Жыл бұрын
Thank you for this great video. Please at 16:14, I cant see well the parameters of RelayCommand execut:0:oject=>{...} doesnt work for me, i had to rewrite as a function. do you mind ,please, to post only that part here? thank you again for this great job very helpful
@mindsetiseverything6362
@mindsetiseverything6362 Жыл бұрын
Same error
@sgsmawesh
@sgsmawesh 8 ай бұрын
This is what i needed, and you explained well, however did not figured out what is (???) at 17:26 , I had to remove it for me to work.
@Malcrom1967
@Malcrom1967 Жыл бұрын
Well I got through this toward the end but new RelayCommand(execute: o:object => gives errors.
@tronaitor0
@tronaitor0 Жыл бұрын
Beautiful, you cant imagine how long I have been looking for this, it is exactly what I needed. Thanks!
@_buffer
@_buffer Жыл бұрын
I'm glad you found it useful! :-)
@megachill
@megachill Жыл бұрын
Awesome, would love to see a version using community toolkit and what that would change.
@krzys2sokyami681
@krzys2sokyami681 Жыл бұрын
Agree with this, especially growing popularity of community toolkit, video would be useful
@joeprince7509
@joeprince7509 Жыл бұрын
I second this! Does the new toolkit provide means for navigation using services and DI?
@tronaitor0
@tronaitor0 Жыл бұрын
If you want to use the Community Toolkit, you can simply use derive from Observable Object instead of creating a ViewModel class, and use the RelayCommand provided by the Community Toolkit, at least that is what I've done and works like silk.
@charlesgantz5865
@charlesgantz5865 Жыл бұрын
What does (???). in the various Path's mean?
@Cary581
@Cary581 Жыл бұрын
I have the same issue. I have never seen this before.
@magictorte6022
@magictorte6022 7 ай бұрын
this video just saved my life. I had some code with very half-baked ideas on how to do exactly this but it just wouldn't work, and spent like 1.5h following along with the steps you take to reform what i had and see the advantages of your approach. And really, it works absolutely beautifully, so thank you even a year later :)
@KalvinKarlNonato
@KalvinKarlNonato 8 ай бұрын
Thank you for this wonderful video. I would like to know if you have this same video without core anymore by using microsoft mvvm please? thank you so much.
@robstark4062
@robstark4062 Жыл бұрын
Thank you for this tutorial, I must say it is the simplest I ever watch. For the next can you make a tutorial about passing data using this navigation. Thank you!
@Luke-il4ln
@Luke-il4ln 28 күн бұрын
Hi. Thanks for great video. Fast question. I'm having a scenario that require to show same window multiple times (same View and ViewModel) but with other data. My question is : Do viewModels need to be singletons ? I think not, but maybe I'm missing something.
@gamegame4713
@gamegame4713 Жыл бұрын
Thank you for this video, very helpfull, i was wondering how to pass parameters with navigation, i changed the factory from Func to Func so i can pass parameter as an object, but i don't know if this is the right way, even if it works
@calvindale
@calvindale Жыл бұрын
I saw another example where an AppHost is used to manage the DI container: kzbin.info/www/bejne/mn21kHdofq94Z68 . I wonder what the benefit the AppHost brings versus the ServiceCollection approach used in this video.
@Harmeet50
@Harmeet50 Жыл бұрын
Absolutely amazing. Right what I was looking for. After searching for this on You tube and Linked, landed on this video after many months. Thanks for your help.
@_buffer
@_buffer Жыл бұрын
I'm glad you foudn something that was useful! :-)
@johanmilterjakobsen1627
@johanmilterjakobsen1627 Жыл бұрын
Really nice video, i have learned a lot from you and this video! One thing though im a bit confused of is how do to set the other ViewModels DataContext? Its just i have tried something, that doesnt work the way i expected... You can try it youself by deleting the MainViewModels ButtonBindings, and then try to press the buttons on either HomeView or SettingsView. When i try it, it doesnt work?
@yobofunk5689
@yobofunk5689 Жыл бұрын
Thank you. Wouldn't it be a bit more modulable if instead of derivating the Core, having a IServiceNavigation interface ? Then simply init the class with the navigation, then its command... Nit picking I guess, but it woudl feel more reusable.
@eassgermany4267
@eassgermany4267 11 ай бұрын
@Payload what is the name of IDE you used?
@_buffer
@_buffer 10 ай бұрын
Rider :-)
@nagyabel937
@nagyabel937 Жыл бұрын
is it working under .NET 6?
@_buffer
@_buffer Жыл бұрын
Yep, it works across all .NET Versions > 4.5
@sperreault
@sperreault Ай бұрын
This is fantastic - it really drove home the different pieces and how they work together. Thank you!
@_buffer
@_buffer Ай бұрын
Thank you! And you're most welcome :-)
@РоманВласик-ь9и
@РоманВласик-ь9и Жыл бұрын
Hello Payload! I have a question. Maybe it`s kinda stupid question. So, should i use MVVM when i have a lot of different windows with different functionality (I am making diary, and there I have MENU window and other window where I working with all that writing stuff)? So, I have 3 groups (1.Main menu window and window with all writing and editing stuff, 2. account settings and customizing window to change look of main menu window (i have button on main menu window to navigate to them) 3. Login and registration). I guess they would look good with MVVM, but i am not sure if they can be putted together like that. Should i put all those windows that i work with, right into folder MVVM, and working there with those groups? Thank you in advance
@_buffer
@_buffer Жыл бұрын
Good question! If you join the Discord it'll be easier to help you :-)
@JiaMingYew
@JiaMingYew Ай бұрын
What IDE is this, it looks minimalistic and great !
@gahshunker
@gahshunker Ай бұрын
A comment to satisfy the KZbin gods…theeeereee youuu gooo
@white5096
@white5096 Ай бұрын
When clicking Home error goes System.Windows.Markup.XamlParseException: 'Page can have only Window or Frame as parent.'
@white5096
@white5096 Ай бұрын
Error was indeed in xml file. You need to make sure its `UserControl` class and not any other
@asrielknight
@asrielknight Жыл бұрын
hey! i know its been like 7 months since you posted this but is there any way you could tell me how id set a default CurrentView? i want the homeview i have to be a navigation hub and i cannot for the life of me figure it out. thanks! edit: also, how do i pass in a variable to a view im switching to?
@deadlyremix4115
@deadlyremix4115 Жыл бұрын
in your OnStartup method in App on the video, put var navService = _serviceProvider.GetService(); navService.NavigateTo(); and to the second question, i think you need to get rid of the in-line delegate when defining NavigateHomeCommand for example and instead pass in an actual function which can change the properties of a class which other viewmodels can access. hope i could help a little bit
@dundorma
@dundorma 11 ай бұрын
You can do this by calling the NavigateTo function in the MainViewModel like this public MainViewModel(INavigationService navService) { Navigation = navService; NavigateToHomeCommand = new RelayCommand(o => { Navigation.NavigateTo(); }, o => true); NavigateToSettingCommand = new RelayCommand(o => { Navigation.NavigateTo(); }, o => true); Navigation.NavigateTo(); }
@abnrml5452
@abnrml5452 4 ай бұрын
what ide Is that
@_buffer
@_buffer 4 ай бұрын
Good question! It's called Rider and it's developed by JetBrains!
@ShiruHDani
@ShiruHDani 2 ай бұрын
Very great video, as a beginner this was very good to understand and it works perfect in my wpf app! The only thing that I wish would also be in this video is how I can still do pop-ups when needed. I thought of something more generic like using the constructor of the view model of the user control to set the height and width and stuff, so that the view model base class does the stuff for it. I just can't think of a way to do it with dependency injection. Any advice? But still thank you so much for this video and keep it up! :D
@ShiruHDani
@ShiruHDani Ай бұрын
welp, I got the pop out thing myself lol
@DonaldFranciszekTusk
@DonaldFranciszekTusk Жыл бұрын
It's so complicated :/ I don't understand why this is such a different approach from what you used to switch views before. In your previous video ('Modern UI app') you made it much simpler, just reassigning CurrentView with Command on click, and switching between views worked the same. Couldn't it be done as easily as in that video? I appreciate that you show how something is done, but if this is supposed to be a tutorial, it would be better if you did a longer introduction before doing it, what and why exactly you want to do.
@repossession
@repossession Жыл бұрын
This can absolutely be done in the simpler way that you mentioned. The difference in approach (and level of complexity) is a result of using the MVVM design pattern and Dependency Injection. Using MVVM and DI simply adds some benefits (e.g. easier unit testing, reduced overall complexity once you hit a certain app size) that some may feel are worth the added complexity, and it's those people that this video is targeting.
@DonaldFranciszekTusk
@DonaldFranciszekTusk Жыл бұрын
@@repossession ok
@m0lDaViA
@m0lDaViA 5 ай бұрын
Wait so you don't use pages for navigation?
@ricardocasillas5054
@ricardocasillas5054 Жыл бұрын
Great tutorial. Totally cool, simple but effective. where can we get the source code, save me some key strokes. Thanks,
@_buffer
@_buffer Жыл бұрын
Thank you! And the source code can be found over at my Patreon www.patreon.com/payloads
@bernhardbunnenberg9889
@bernhardbunnenberg9889 9 ай бұрын
Thanks alot. Fast and comprehensive information I needed. It's rare to find so much information in such a short video.
@_buffer
@_buffer 9 ай бұрын
I'm glad you found it useful! Thanks for the nice feedback!
@nnamdiemetarom1816
@nnamdiemetarom1816 8 ай бұрын
Do you still need OnPropertyChanged in the setter of the Navigation property in the MainViewModel Class. There is already an OnPrpertyChanged in the setter of the CurrentView of the NavigationService
@goosee980
@goosee980 3 ай бұрын
I was completely lost i my WPF project, since i started it just today, but you helped me so much!!!! Now the project looks structured, it works and i learned a lot! thanks for such a great video!
@chriswinslow
@chriswinslow Жыл бұрын
Great tutorial. But the volume is a little on the low side.
@ReturnTypeVoid
@ReturnTypeVoid Жыл бұрын
You sure it’s not on your side bud, volume is fine for me!
@_buffer
@_buffer Жыл бұрын
Thank you! The volume seems fine on my end too actually :-)
@przemosz7337
@przemosz7337 5 ай бұрын
Deffinitly best tutorial videos on wpf on YT. Thanks mate Also those videos on how to make Flat Design they are perfect
@deegodoub
@deegodoub Жыл бұрын
For some reason "ContentControl" in MainWindow is displaying the name of the viewmodel class file name rather than display the view that it's associated to?
@benkenobii2057
@benkenobii2057 Жыл бұрын
How to set child view model properties from parent? When i do that, the child User Control displayed on the main window parent does not change its properties, i have set the data context
@alansebastian3518
@alansebastian3518 6 ай бұрын
I hate youtubers like this. who don't even share the code if we don't pay.
@jammyg1779
@jammyg1779 16 күн бұрын
lazy ahhh
@fainergame3842
@fainergame3842 Жыл бұрын
Hello, can someone tell me how to make authorization with this code? Those. so that I can log into my account and I can get the UserControl output working.
@MrJayce666
@MrJayce666 6 ай бұрын
Went through this video about 2 weeks ago and was just stumped as to why things were done in certain ways. After leaning more about the need for ObservableObject and RelayCommand I came back to this video today and just breezed through it. Really good video. Thank you
@su-remarked
@su-remarked Жыл бұрын
I have similar code but I dont need creating new instance of viewmodel every time I change views. I have a lot of data that viewmodels are storing and this method of changing views would terribly slow down the program
@andreim2981
@andreim2981 Жыл бұрын
What if you open windows? Do i register the view models as transient? It is complicated when you have to use child forms
@su-remarked
@su-remarked Жыл бұрын
Does this code create new instance of someViewModel every time you change views? how to create and use only 1 instance for every viewmodel?
@on4ayl
@on4ayl 11 ай бұрын
Great video. I had to use a magnifying glass to view the code. Font is too small.
@botlife6386
@botlife6386 Жыл бұрын
can u do a updated version of the chat hub with a login and setup the database but make it where it saves the last chats and how to add calling and video chat and make it a add function plz
@mattaku9430
@mattaku9430 Жыл бұрын
Oh man, a service locator, can we do it without the service locator?
@j4ck3
@j4ck3 Жыл бұрын
Hello, nice tutorial. just wondering if there is a simple way to pass parameters to other viewmodels when navigating to one?
@adammakota
@adammakota Жыл бұрын
And how to allow Dependency Injection for Views eg. if someone what's to inject EventService into View.cs how would you do that?
@AndrzejKlonowski
@AndrzejKlonowski Жыл бұрын
did you get how to pass parameter to viewmodel? I want to open details of client (to edit), but I don't know how to do that
@AndrzejKlonowski
@AndrzejKlonowski Жыл бұрын
wow, I can't believe it, I asked chatGPT how to do it and he answered with working code :)
@gregh2469
@gregh2469 Жыл бұрын
​@@AndrzejKlonowski Similar to how you set the DataContext when instantiating the MainWindow to the MainWindowViewModel you could initialize any property in your ViewModel when adding it to the serviceCollection. Additionally, since this should be an instance of your ViewModel, the work done in your constructor should be processed as well.
Жыл бұрын
Thank you for this great tutorial! As a newbie this was really informative.
@_buffer
@_buffer Жыл бұрын
Heck yeah! I'm glad you found it useful! :-)
@ignaciodelaparra
@ignaciodelaparra 8 ай бұрын
Great video, you got a new subscriber (:
@ІП-21ПавлусенкоДанилоОлегович
@ІП-21ПавлусенкоДанилоОлегович Жыл бұрын
are UserControls created every time we click a button to go to them, or they have only one instance?
@1mSeraph
@1mSeraph 7 ай бұрын
Hi i applied this method for my new project and it ran fine for a while, however now i am getting sudden Errors in my app.xaml telling me that my sources that i use for my viewmodels and views do NOT exist within the previously used and until then working namespaces. I tried reloading the folders into the project but to no success. Its beginning to get really frustrating as i am no longer able to compile my project. Does anybody know how to handle this?
@GoodbyeMrX
@GoodbyeMrX 7 ай бұрын
You need to change in your App.xaml StartupUri="MainWindow.xaml"> to StartupUri="MVVM/view/MainWindow.xaml">
@someone150
@someone150 Жыл бұрын
What keyboard do you use?
@_buffer
@_buffer Жыл бұрын
Custom keyboard with nk_sherbet switches :-)
@Pdxron
@Pdxron Жыл бұрын
whys bro awake at this time
@_buffer
@_buffer Жыл бұрын
Because content! :D
@MoraisNelson1407
@MoraisNelson1407 Жыл бұрын
I'm stuck at 16:12. where you do NavigatoToHomeCommand = new RelayCommand(execute: O :object.... I get a bunch of errors, starting with the fact that O is unknown...
@neverever2630
@neverever2630 Жыл бұрын
new Relaycommand(o => ...) get rid of execute::Object
@natlinux
@natlinux Жыл бұрын
I was so happy to finally see a video again. greate job
@_buffer
@_buffer Жыл бұрын
Thank you! Happy to see that you're still around! :-)
@natlinux
@natlinux Жыл бұрын
@@_buffer 💚💚💚
@amied658
@amied658 Жыл бұрын
This was amazing. Thank you so much. 👍
@_buffer
@_buffer Жыл бұрын
You're most welcome! :-)
@Andrei-qi4tm
@Andrei-qi4tm Жыл бұрын
Very useful what you did here!
@_buffer
@_buffer Жыл бұрын
Thank you! I'm glad you found it useful! :-)
@Stor_Man
@Stor_Man 10 ай бұрын
Which theme do you use in Rider?
@nguyenminhduc98b2
@nguyenminhduc98b2 10 ай бұрын
nice video, it helps me alot!
@zakiisse7519
@zakiisse7519 Жыл бұрын
Fantastic tutorial!! 😊
@_buffer
@_buffer Жыл бұрын
Thank you so much! :-)
@Yousef_Mohammed-I
@Yousef_Mohammed-I Жыл бұрын
nice
@_buffer
@_buffer Жыл бұрын
Thank you Yousef! :-)
@abner_pm
@abner_pm Жыл бұрын
great job🤪
@onyekaidika355
@onyekaidika355 Жыл бұрын
Amazing as always ❤️
@expatca4444
@expatca4444 6 ай бұрын
What a complicated mess only to do that. I should be a more simpler way
@gahshunker
@gahshunker 4 ай бұрын
😂 i can't believe this either. looks like an April fool's joke. this ain't "easy"
@haku5957
@haku5957 Жыл бұрын
ty bro
@_buffer
@_buffer Жыл бұрын
Anytime! :-)
@haku5957
@haku5957 Жыл бұрын
I had a problem yesterday about navigation. So, maybe u can help me. I have 4 different UserControls (views) on 1 page with one GlobalVoewModel. I had to switch (navigate) on one of UCs without changing the others. It's was very difficult and I came to solution by just using flipper element from MeterialDesign, but I actually don't like it. Any advices, payload?
@haku5957
@haku5957 Жыл бұрын
@@_buffer bro
@_buffer
@_buffer Жыл бұрын
@@haku5957 Sounds like a design issue, feel free to hop in the Discord, will be easier to help you over there :-)
@王嵩-l4s
@王嵩-l4s Жыл бұрын
Thank you very much for this great video. I studied a lot by myself, finally I can do it. BTW, may I ask that, is it possible to do a multi-navigation. For example, 2 views in 1 window, and there are 2 subviews in one view of window. It can be contentcontorol or tabcontrol. Thanks.
@AhmetYigiter
@AhmetYigiter 7 ай бұрын
Look at view model locator concept
@berke.code07
@berke.code07 Жыл бұрын
Layne was better
@JakubMieszkowski-r7y
@JakubMieszkowski-r7y Жыл бұрын
beautiful #FFE51400
WORLD BEST MAGIC SECRETS
00:50
MasomkaMagic
Рет қаралды 54 МЛН
Will A Guitar Boat Hold My Weight?
00:20
MrBeast
Рет қаралды 256 МЛН
Как мы играем в игры 😂
00:20
МЯТНАЯ ФАНТА
Рет қаралды 3,2 МЛН
Running With Bigger And Bigger Lunchlys
00:18
MrBeast
Рет қаралды 115 МЛН
Refactor Your App to The MVVM Community Toolkit (feat. WPF!)
30:34
SingletonSean
Рет қаралды 11 М.
WPF C# Professional Modern Flat UI Tutorial
36:44
Payload
Рет қаралды 822 М.
Is LEARNING WPF still WORTH it in 2023?
10:59
tutorialsEU
Рет қаралды 51 М.
WPF INotifyPropertyChanged and Databinding
14:30
Payload
Рет қаралды 40 М.
WPF C# How To Create Your Own Modern VPN Tutorial
59:21
Payload
Рет қаралды 31 М.
The Home Server I've Been Wanting
18:14
Hardware Haven
Рет қаралды 169 М.
How much does the Windows Community MVVM Toolkit REALLY help us?
7:02
Dependency Injection, Generic Host, and WPF
2:44:29
Kevin Bost
Рет қаралды 7 М.
WORLD BEST MAGIC SECRETS
00:50
MasomkaMagic
Рет қаралды 54 МЛН