Switching Views - WPF MVVM NAVIGATION TUTORIAL #1

Поделиться
HTML-код
  • Опубликовано: 2 июн 2024
  • Learn how to setup the infrastructure for navigation in an MVVM application. Implementing this infrastructure makes common navigation scenarios, such as switching views, very easy to achieve throughout the application.
    Navigation is an essential piece of an application. In this series, I demonstrate how to implement various navigation scenarios in a WPF MVVM application.
    TIMESTAMPS:
    0:00 - Introduction
    0:43 - Demo Introduction
    1:13 - Mapping View Models to Views
    3:30 - Managing Navigation State (NavigationStore)
    5:15 - Adding a Navigation Command
    5:58 - Using the NavigationStore and Navigation Command
    7:29 - Handling CurrentViewModel Changes
    10:07 - Adding More Navigation Commands
    11:28 - Cleaning Up Navigation Commands
    14:11 - Testing
    14:19 - Summary
    15:14 - Conclusion
    VIEW MODEL COMMUNICATION: • View Model Communicati...
    SOURCE CODE: github.com/SingletonSean/wpf-...
    💎 Become a Member: / @singletonsean
    🏠 Discord: / discord
    🐤 Twitter: / singletonsean_
    🏆 Donate: www.paypal.com/donate?hosted_...
    ✉️ Email: youtube@singletonsean.com
  • НаукаНаука

Комментарии • 164

  • @katlegorambau662
    @katlegorambau662 2 года назад +10

    When I discovered this channel, I told my friends I found heaven. Absolutely amazing.

    • @SingletonSean
      @SingletonSean  2 года назад +1

      Thanks KATLEGO, that's wonderful to hear!

  • @florinchess
    @florinchess 2 года назад +24

    This tutorial is amazing! I've been trying to figure out navigation on my own, but couldn't get it to work as I wanted to. I did some research on the Internet for some possible solutions and was surprised to find out that the area of navigation in WPF is poorly documented. Thankfully I found your channel which helped me solve my issue and for that, I am very grateful!
    Big thumbs up from me! Keep up the great work!

    • @SingletonSean
      @SingletonSean  2 года назад +5

      Thanks Zamfir, and I completely agree. It's bizarre that it's so difficult to find tutorials for something as simple navigation. Glad these tutorials are helpful!

  • @younguklee
    @younguklee Год назад +2

    This is one of the greatest teaching videos i've ever seen about wpf! Thanks for your this clip I learned lots of things about WPF and mvvm. Thanks.

  • @MrSeagull1
    @MrSeagull1 3 года назад +1

    Really glad this has no dislikes. Great quality tutorial! :)

  • @juancadiy5207
    @juancadiy5207 3 года назад +1

    bro, no words thanks a bunch, I haven't finished watching but I feel I own you already

  • @mazingguitar
    @mazingguitar 2 года назад

    Great job there! It's simple and very powerful.

  • @joeyk2250
    @joeyk2250 3 года назад +1

    Great video! nice structure and I enjoyed the summary at the end very much

  • @jackkendall6420
    @jackkendall6420 2 года назад

    Superb video. Exactly what I wanted to see!

  • @naberius81
    @naberius81 Год назад +1

    Sean great tutorials, thank you. I was looking for a nice and simple way for navigating between views and it is interesting how you solved it with navigation store. Please tell me what do you think of making a MainView model like a singleton and inside it you could have the logic for changing the viewobjectplaceholder parameter in any way you want. And if you want to change the view from any model you can just reference the singleton mainviewmodel without having to pass arguments for navigation store and similar ?

  • @genelarose3055
    @genelarose3055 3 года назад +4

    finally..... this was needed...thank you!

  • @iliyanangelov
    @iliyanangelov 3 года назад +5

    Absolutely amazing. Code is clean, explanations are straightforward. Subscribed!

  • @kringe6397
    @kringe6397 2 месяца назад

    and again coming in clutch with another banger tnx bro

  • @anilkumarsirigiri1441
    @anilkumarsirigiri1441 2 года назад +7

    Hi, a great and very useful tutorial. However, as a beginner I am running into binding problems and other debug errors while following your video and implementing in my practical application. If I see your source code, it contains the end source code after all tutorials. Is it possible to have the code after 1st tutorial itself? As every class is not clearly shown in the video, I would like to examine my mistake going through the code. If the code after the first tutorial is not available, then it would be grateful if you le me know how you set datacontext in app.xaml. I see in app.xaml a number of functions. Thanks in advance.

  • @15wojto
    @15wojto 3 года назад +1

    Thank you for this viedo. I've been watching your movies for some time, for example WPF simple trader series. You gave me a lot of knowlage in WPF but a naviation wasnt enough clear for me. I appreciate it and I hope to see the best approach to navigate in WPF here :)

    • @SingletonSean
      @SingletonSean  3 года назад

      Hey Wojciech, glad you appreciate the content. I'm sorry to hear this tutorial wasn't clear. I'm willing to help out in the comments if you have any questions regarding navigation.

    • @15wojto
      @15wojto 3 года назад

      @@SingletonSean The tutorials was clear ! Im just beginner and this is a reason :)

  • @sagarsalunkhe6429
    @sagarsalunkhe6429 3 года назад +2

    Your work is amazing...Best Video I have seen so far ...Thanks a lot.

    • @SingletonSean
      @SingletonSean  3 года назад

      Thank you Sagar, that is quite the compliment!

  • @nivien7220
    @nivien7220 2 года назад

    dude, you are a godsend. Thank you so much, finally I understand it AND can implement it. Will deffo check out more of your videos

    • @SingletonSean
      @SingletonSean  2 года назад +1

      Thanks Nivi, glad this was helpful!

  • @alvinyanson
    @alvinyanson 2 года назад +3

    Thanks for this. Just my sentiment, would it be possible to provide a separate git branch for each video? Great tutorial

  • @ymchen168
    @ymchen168 Год назад

    This is very helpful for a WPF beginner like me. I have a question, what is a good way to implement if I want to make the corresponding button text in the NavigationBar bold for the active view?

  • @livewithcedric8336
    @livewithcedric8336 3 года назад

    Very clean and precise tutorial. Yes I'm now a subscriber.

  • @temptica7982
    @temptica7982 3 года назад +1

    Hey, I got this main window, and I got 4 user controls where they fill in data. I want to save the data from those usercontrols using MVVM so I can read data from the server and fill it in, or read from the models to the server and make a graph from the data. Can you make a tutorial simular to this? or did you already made a tutorial about databinding using multiple usercontrols? Thank you in advance. I've been struggling with this for over a month now

  • @nicolabirro1167
    @nicolabirro1167 Год назад +1

    Hi Sean, thank for the video.
    I saw that a type registered with AddTransient does not garbage collect and cause memory leak. I read that this happen when the type implement IDisposable (all viewmodel of this demo). Have you ever seen this problem / do you know some way to solve this problem? Thanks!

  • @alewarten
    @alewarten 2 года назад +1

    Great series of the videos! Is it possible to prevent view recreation every time we switch between views?

  • @NoAlias536
    @NoAlias536 2 года назад

    Excellent tutorial!! Now i'm trying to figure out how to move backwards and fordwards... i use the NavigationMVVM project to do some experiments and it works pretty well when i need to navigate to a view, but i don't know how to save the views created and move forwards and backwards...

  • @wayneunited59
    @wayneunited59 3 года назад +1

    Hi Sean great videos again. I was wondering if you have any experience with Prism or MEF. Or maybe any decent resources for getting a grip on them.

    • @SingletonSean
      @SingletonSean  3 года назад

      Thanks AY AY RON, I have a bit of experience with Prism. The Prism docs are actually well structured, so I think they would be a good starting point. I'm interested in taking on a short series with Prism in the future.

  • @WillEhrendreich
    @WillEhrendreich 3 года назад +1

    Nice, sean! Thanks! If I ever get into a situation where I can't use PrismLibrary I'm coming straight to this video again!

    • @SingletonSean
      @SingletonSean  3 года назад

      Thanks Will! It seems like you'd prefer if I used Prism, haha

    • @WillEhrendreich
      @WillEhrendreich 3 года назад

      @@SingletonSean haha, no, I think Prism is freaking awesome, but I think that any framework is a possible liability, and so I think if there's any way to it, actually understanding how you can do that exact thing without needing the library.. especially if the thing you're tying yourself to doesn't always work the way you need it to. So, In short, I'm super grateful for the great explanations as always. I'm going to learn this, so I more thoroughly understand how to do everything.

  • @paulegan3783
    @paulegan3783 3 года назад +3

    Thanks! Sorry if this is a silly question, but if you always set your CurrentViewModel to a new instance of e.g. AccountViewModel or HomeViewModel whenever you navigate, do you not end up with duplicate instances of each view model?

    • @SingletonSean
      @SingletonSean  3 года назад +4

      That's a great question Paul! They are new instances each time. However, the previous instance will get cleaned up by the garbage collector. I will be discussing this more in depth later in this series when I mention the importance of disposing view models.

    • @paulegan3783
      @paulegan3783 3 года назад

      @@SingletonSean Fantastic, thanks again

  • @samuelillouz4979
    @samuelillouz4979 3 года назад +3

    aaahhh thanks guy !!! u did it !!!

  • @niljakvic148
    @niljakvic148 Год назад

    Hi sean, I wondered how to make the 'contentcontrol' generic, like a ViewModelHost, it's a control, it can binding any viewmodel you want.

  • @gabrielanton4319
    @gabrielanton4319 3 года назад +1

    Nice videos.
    A tip. Do you know that you can have design time data context in your xaml view? That way you can make use of the intelisense while keeping the mvvm intact.

    • @SingletonSean
      @SingletonSean  3 года назад +2

      Good tip Gabriel! I remember back in my Xamarin days I would always use it. For some reason I don't use it much in WPF. I suppose just because I usually develop with my view model and view side by side nowadays. Still a very useful tool. Thanks for the feedback and suggestion!

  • @Robin-uu4wx
    @Robin-uu4wx 3 года назад

    Hey Sean, i have a question. So we're basically decoupling the different ViewModels for navigation, but when we call the NavigateCommand, we need to pass the type of the ViewModel to the NavigateCommand. Shouldn't we want to decouple this as well with some form of Mapper. Like, we pass a string with a name, like "AccountViewModel", and something like AutoMapper maps a corresponding Type with it. That way we have completely separated our ViewModels from each other, or am i missing something?

    • @SingletonSean
      @SingletonSean  3 года назад

      Hey Robin, that might be a possible solution, and that's a good point noticing that coupling. However, I actually remove the generic type from the NavigateCommand in a later video.

    • @turn1210
      @turn1210 2 года назад

      Normally what I do is have an abstract base class for viewmodels that has a ViewName property, and a ICommand that passes the VM itself to wherever the navigation store is as the new active view. This gives the flexibility to represent the viewmodels as a button to navigate, or a full blown view in XAML

  • @benjaminlaunicke1256
    @benjaminlaunicke1256 2 года назад

    Hey SingletonSean! Is there some how a way to further use Live-Binding of Visual Studio while passing parameter in the constructor of the ViewModel ? By doing this, it breaks the Live-Binding feature. I tried the ViewModelLoccator Pattern and it works ... sort of. Could you maybe have a look into this at some point ? Thanks for your videos ! :)

    • @SingletonSean
      @SingletonSean  2 года назад

      Hey Benjamin! That would be a muchhh nicer developer experience if we could find a way to get that working. I'll take a look, thanks for the suggestion!

  • @kezwikHD
    @kezwikHD Год назад

    great tutorial, thank you!
    But i've got a quick question:
    How is the Datacontext set for the View?
    How does homeview know whom to bind to?
    I am a bit lost here

  • @anonymousdesu5335
    @anonymousdesu5335 2 года назад

    great as always , can you make a video on opening a small window from the main window in the mvvm approach ?

  • @guillaumemuc8753
    @guillaumemuc8753 2 года назад

    Amazing !!!!

  • @fatmamakhlouf4431
    @fatmamakhlouf4431 2 года назад +2

    Great video! it's very helpful, but when i start the application, there are two windows that display for me, is there any solution for this problem?

  • @riyadamrani
    @riyadamrani 3 года назад +2

    Hi Sean, thank you for the video. What if one ViewModel can navigate to many other ViewModels ? You would have to pass to that one ViewModel all the parameters required in the constructors of the many other ViewModels. I don't really like that, I would you do it ?
    Thanks !

    • @SingletonSean
      @SingletonSean  3 года назад +2

      Thanks for the feedback Riyad. I hope I'm interpreting your question correctly. This seems like something that could be solved by the factory pattern. I suppose your question will be answered in the video where I setup dependency injection to clean everything up (I think that'll be one of the final few vids unfortunately).

    • @riyadamrani
      @riyadamrani 3 года назад

      @@SingletonSean I checked the Github source for "wpf-tutorials/NavigationMVVM/" and it looks like you cleaned it dependency injection after this video. It is much butter thank you :)

  • @billyjones7347
    @billyjones7347 2 года назад

    Is there a way to only load the views, particularity the home view once after start up vs recreating them each time the CurrentViewModel changes? My HomeViewModel will hit a database triggered by a behavior defined in the HomeView that loads a list to display. The problem is once I navigate away and come back to the HomeView, it will create a new instance and do it all over again resulting in multiple unnecessary trips to the DB and duplicating data. I got around it by checking if the list already contains items but would like to avoid the recreation of the views altogether, if possible with this approach.

  • @ahmedezzat6111
    @ahmedezzat6111 3 года назад +1

    Hi, Thanks for the video, I have a little question, what is the code behind for the navigation buttons? I cant figure it out thanks again

    • @zerosandones7547
      @zerosandones7547 2 года назад

      NavigateAccountCommand is defined in HomeViewModel.

  • @scotolivera8207
    @scotolivera8207 2 года назад

    Wow, finally thanks a lot

  • @shubhampandya6450
    @shubhampandya6450 3 года назад +3

    Thanks a lot sir... Please upload more videos on wpf series coz not any good channel on RUclips about wpf ...

    • @SingletonSean
      @SingletonSean  3 года назад

      Thanks Shubham, that is indeed the goal!

  • @user-on2qy8tw7y
    @user-on2qy8tw7y 2 года назад

    Awesome Video, btw how do I set the Data Context for each?

  • @MrDeylann
    @MrDeylann 2 года назад

    keep it up more video for WPF, i hope you can do a reactive UI tutorial too.

  • @TheWatcher080
    @TheWatcher080 2 года назад

    Hello, it's a great tutorial and I love it. At first I didn't understand so I ended up retyping your code and I finally understand what this approach is about.
    I have a question. How to pass parameters in this approach? I want to display user's data in a view. I believe one way to do that is to pass user object when navigating into a user detail view. Could you please point me to the right direction?

    • @SingletonSean
      @SingletonSean  2 года назад

      Hi Watcher! Part 3 of this series goes into passing parameters, so I would suggest checking that out.

  • @wvvwwwvvw
    @wvvwwwvvw Год назад

    I do have a question about the Store concept here. In case I need to keep settings and I would like to have them loaded through the ConfigurationManager of System.Configuration, would I need to wrap them into a SettingsStore? Especially, if I want to change settings that should affect the other parts of the application, such as the API URI base of the HttpClient class? (hmm)

    • @SingletonSean
      @SingletonSean  Год назад

      That's a good point Aleksandr! For the sake of propagating changes to an HttpClient, it depends on when the HttpClient would read the new setting. If the HttpClient will automatically read the new value from the ConfigurationManager, then I think you wouldn't need the SettingsStore. However, if you expect that you'll need to manually update the HttpClient, then you'd likely need to implement a SettingsStore so that you could manually pass the new settings to the HttpClient.
      Lastly, if you want any settings changes to update the UI, you'd certainly want a SettingsStore so that you could raise an event and raise any PropertyChanged events for the UI to update.

  • @tcgupta5
    @tcgupta5 3 месяца назад

    Hi Sean, How do I switch views with the concept of ListingView(on the left) and DetailsView(on the right) like your other video of Build a WPF MVVM Application - START TO FINISH TUTORIAL. Different views in the DetailsView display according to the clicked buttons in the ListingView

  • @aungmyokhaing8827
    @aungmyokhaing8827 8 месяцев назад

    Thank you so much.

  • @TheLinkedList
    @TheLinkedList 3 года назад

    Great concept and tutorial, however I'm a little confused as to why you don't use the in built Frame, Page and NavigationService that comes with WPF rather than swapping out View Models and mapping navigation at a very top level (Application class)? It seems like reinventing the wheel and abstraction for the sake of abstraction.

    • @anonymousannoyingmouse
      @anonymousannoyingmouse 2 года назад

      not really sure about what you are talking about since im new to WPF, but in my speculation this gives more control to the navigation method while giving the freedom to override some methods that might not be override if used the built framework?

  • @florent9555
    @florent9555 2 года назад

    Does this work also with uwp? Because in my xaml files in the uwp app I have Page tags that surround all the code. In wpf you have Window tags. The Datatemplate stuff does not work for me

  • @dynamic_pointer_cast
    @dynamic_pointer_cast 2 года назад

    Is it okay to use IValueConverter in the binding of Content to convert the viewmodel?

  • @WahidRezgui
    @WahidRezgui 3 года назад +1

    Hi, I followed you in the full stack WPF series and the navigation was not done this way, do you suggest that I change it to an implementation like this one it looked easier for me, the renavigate was not easy for me to assimilate

    • @SingletonSean
      @SingletonSean  3 года назад +2

      Hey Wahid, I'm glad this approach was easier to understand! The full stack series implementation and this implementation should be pretty similar. I think the main differences are that in the full stack series I call the INavigationService an IRenavigator, and I call the NavigationStore the Navigator. Other than that, the concepts should be the same, and you should be okay with leaving your infrastructure the same as it is.

    • @WahidRezgui
      @WahidRezgui 3 года назад

      @@SingletonSean many thanks for the response 🙏 (quick response😊)

    • @Freakhealer
      @Freakhealer 3 года назад

      @@SingletonSean related question: you did the DataTemplates on the App.xaml now you did on MainWindow.xaml any particular reason for that?

  • @BogdanAndreiRO
    @BogdanAndreiRO 3 года назад +2

    100th like, also nice video!

    • @SingletonSean
      @SingletonSean  3 года назад +1

      Thanks Bogdan, and nice job smashing that like button for the 100th time

  • @user-pw3pu8wu3f
    @user-pw3pu8wu3f 2 года назад

    Whats the difference here between the homeviewmodel and the mainviewmodel? When you start the application should it use the main or homeviewmodel?

  • @UserUser-sh6wi
    @UserUser-sh6wi Год назад

    What if the view you wanted to navigate to depended on some logic. Say for example an option the user selected (think an application with steps, like an installer or a cleaning utility). Would you pass every possible navigation service to the viewmodel and let it chose which one to call? Or would there be a better solution?

    • @SingletonSean
      @SingletonSean  Год назад +1

      Hi User! I would create a custom Command that takes the view model and the navigation service through the constructor. This would allow the view model to stay simple, and the command could handle the logic that determines the navigation.
      For example, see this LoginCommand that I implement in another series: github.com/SingletonSean/secret-message/blob/master/SecretMessage.WPF/Commands/LoginCommand.cs#L39
      If the login was successful, we navigate to the Home page. If it failed, we do not navigate at all.

    • @UserUser-sh6wi
      @UserUser-sh6wi Год назад

      @@SingletonSean Okay so just to make sure I understand correctly. Lets say you had a X number of views the login command could navigate to. Would you pass X number of navigation services to the LoginViewModel? I feel like after 2 maybe 3, this would get really dirty.

  • @the_null
    @the_null 2 года назад

    hi bro, i have a question : How to load and unload a heavy view asynchronously ? When I try to open or changed the view, the program slows down. Can you guide me with a few small hints?
    ty for everythings!!!!

  • @JansthcirlU
    @JansthcirlU 3 года назад +2

    Hey Sean, are you looking forward to MAUI? Love the videos, very pragmatic!

    • @SingletonSean
      @SingletonSean  3 года назад +1

      I am looking forward to it! Having a unified platform will be helpful. Hoping the development experience is enjoyable on initial release.

    • @MushokuThing
      @MushokuThing 3 года назад

      @@SingletonSean But it won't be a unified platform? You'll still need alternative UI libraries for anything linux, MAUI will only support Windows, MacOS, and Mobile Devices.
      If you want true a UI across all desktop platforms, look into AvaloniaUI. It's what MAUI should have been from the get go.

  • @dynamic_pointer_cast
    @dynamic_pointer_cast 2 года назад

    Wait, did the DataTemplate in the Content.Resources just bind automatically? I thought there gonna be like

    • @SingletonSean
      @SingletonSean  2 года назад

      Correct Tito, it is automatic (kind of)! Let's take the example of the Content property for the ContentControl being a HomeViewModel:
      1. The ContentControl basically asks "how the heck do I render this HomeViewModel type?"
      2. We define a DataTemplate with it's Type being for a HomeViewModel
      3. The ControlControl will grab that DataTemplate and render the HomeViewModel with it

  • @capegreg3197
    @capegreg3197 3 года назад +6

    Very helpful, but it would be nice if you didn't move around so fast after adding some code or when you stub code out. Even replaying the video doesn't show what you did.

    • @SingletonSean
      @SingletonSean  3 года назад +4

      Thanks Gregory, and that is a good recommendation. Looking back, I am certainly guilty of this! I'll pay more attention to this in my future videos.

  • @stylem8132
    @stylem8132 2 года назад +4

    Amazing tutorials!
    I have a question: Do you know of any way to keep a view alive when navigating between multiple views? The reason I want to do that is because sometimes a view with big data can take a couple of seconds to load and I don't want it to reload it every time (for example there is a gif in a view and it takes 1-2 seconds to load).
    Again thanks for the great content it's been a life saver!

    • @jadececi7653
      @jadececi7653 2 года назад +2

      I actually wanna know this too.

    • @illmefy6444
      @illmefy6444 Год назад

      Hello. Have you found way to save state of view after changing view? The only way I know I can do it is to create static class that will hold specific ViewModel, and pass this ViewModel at changing view to specific view

    • @stylem8132
      @stylem8132 Год назад +2

      @@illmefy6444 After all I decided to go with an mvvm framework and specifically prism. It has a very easy way to manage view and viewmodels lifecycles using an interface called INavigationAware. The information presented in this video is great if you want to go with completely vanilla mvvm, but for me prism has worked great in a fully fledged application without too much boilerplate code.

    • @illmefy6444
      @illmefy6444 Год назад

      @@stylem8132 i found way but I'm not sure if it is good. I created class AppData, where I store data that I read from file. This app data is stored in MainWindowViewModel and every view model that need any data ( for example specific list from AppData) is passed as constructor to viewmodel

  • @sardissozo3399
    @sardissozo3399 Год назад +1

    I would love a repeat of this tutorial, or something very similar, using the Community.Toolkit.MVVM... from scratch. Nobody seems to have a from scratch tutorial using the toolkit; just samples of editing a program that is already built to illustrate the differences.

    • @SingletonSean
      @SingletonSean  Год назад +1

      Hey Sardissozo, that's a great suggestion! I'll look into the toolkit and make a walkthrough video on it. It would probably help in my own projects too!

    • @danielsutton8262
      @danielsutton8262 Год назад +1

      @@SingletonSean I second this, it would be brilliant Sean if you can mate!

    • @Vitae_Essence
      @Vitae_Essence Год назад

      100% agree with this. I am trying to get it working with the toolkit and I am running into issues as a beginner. Also, while the tutorial was good, I feel like you went way too quick. It's nice to have it in a short video but I would rather have it slowed down a bit and have to skip past some things instead of having to rewind every 10 seconds. If you have watched any of iamtimcorey his style is to take it slow to make sure you really understand what's going on. None-the-less it is still a very helpful video

  • @15wojto
    @15wojto 3 года назад +1

    I have a question. Is posible to open a new window in this kind of navigation? I need a place when user can enter some data after button click, but i dont know how should I do that to dont break MVVM rules and accept your way to navigation :(

    • @SingletonSean
      @SingletonSean  3 года назад +1

      Hey Wojciech, that's a good question. I usually don't open entirely new windows for popups, but I could see that being useful. I'd love to do some experimentation and tack on a video to this series on that topic.
      Alternatively, I'll be showing off how to display modals later in this series, which might satisfy your use case. Thanks for the suggestion!

  • @n_23539
    @n_23539 4 месяца назад

    This tutorial is amazing! I tried to do it but I couldn't because of compiler error. When I start the code I recieve this error message: Window must be the root of the tree. 'Window cannot be added as a visual unit child.'. Because of this error it doesnt work. How can i fix it?

  • @kentswan3230
    @kentswan3230 3 года назад +1

    Was duplicating the tutorial using stop and go on the video but am now frustrated trying to figure out what I messed up. I downloaded the tutorials. I use Beyond compare 4 to analyze differences between projects and found that this finished example wasn't among them (eg the example of the same name is much different). Coul you put this example in the tutorials as NavigationMVVM1 or give it some other differentiating suffix?

    • @SingletonSean
      @SingletonSean  3 года назад

      Hey Kent, the source code is many commits ahead of this video. Luckily, you can view commit history in GitHub! I believe this link is the state of the repository after this video: github.com/SingletonSean/wpf-tutorials/tree/ed841f474a36d7621b2b87c5103bdc05c4d0248b/NavigationMVVM

    • @kentswan3230
      @kentswan3230 3 года назад

      Thanks, huge. Your tutorials are quite helpful in learning various methodologies. I note that the newest commit has implemented dependency injection. I've tried it on my own after following various tutorials but there's something missing in my intrinsic understanding of how to relate the constructor injection with the injector declarations. In particular what happens when you have a singleton entity vs new entity and/or how a new can refer to a singleton (which doesn't sound correct).

    • @kentswan3230
      @kentswan3230 3 года назад

      Downloaded and ran my cross-check. Found a XAML error where I launched the main window twice. My bad. A question though. In looking at my constructors I was, apparently necessarily storing the NavigationStore locally in the HomeViewModel and AccountViewModel.

    • @Freakhealer
      @Freakhealer 3 года назад

      @@kentswan3230 would you let me know what was the issue? i am launching two main windows and i cant figure out why yet

  • @montrianthony5216
    @montrianthony5216 2 года назад

    Dear SingletonSean. I've question about this design, Does it better than you MVVM series that using ViewModelFactory

    • @SingletonSean
      @SingletonSean  2 года назад

      Good question montri, I think the design in this series is much better, more organized, and easier to extend. However, both series follow the same overall concepts.

    • @montrianthony5216
      @montrianthony5216 2 года назад

      @@SingletonSean Thanks again to share your Very good examples to me and to the world, you are very good teacher.

  • @ghosthunter9897
    @ghosthunter9897 Год назад

    Hey dude, I can not navigate AccountView and HomeView if I add them as WPF Window. It only works for User Control. Any suggestion would be appriciated!

  • @matthewkeen6281
    @matthewkeen6281 Месяц назад

    nice

  • @siavash2176
    @siavash2176 3 года назад

    This approach is good for small apps but for large apps you should use something like Prism navigation, you don't have to re-invent the wheel, thanks for the video!

    • @chewingal2324
      @chewingal2324 3 года назад +2

      Exactly! I've been using PRISM for while and love it. Ideal for building loosely coupled apps.

    • @SingletonSean
      @SingletonSean  3 года назад +3

      Thanks for the feedback both of you! I've had great success using this approach in large applications. On the other hand, Prism is a great tool for building MVVM applications. I haven't used it much, but is something I'd consider.

    • @chewingal2324
      @chewingal2324 3 года назад

      @@SingletonSean the learning curve is a tiny bit steep, but the benefits are endless. You definitely should give it a go. Kind regards, Alex

    • @WillEhrendreich
      @WillEhrendreich 3 года назад

      @@chewingal2324 yeah, and Brian Lagunas, the principal maintainer, is a really good teacher , has a great youtube channel, and is very helpful when he's asked a question. I really enjoyed going through his series where he built an Outlook clone, really helped with the prism concepts. But I think I appreciate the videos from Sean because he's going into the mechanics behind what's going on without much extra added. Also, since Brian works at Infragistics, he uses a lot of those wpf controls, which is great, but certainly requires some reinterpretation if you can't drop $1000 on premium controls from a third party.
      I certainly think those have their place, are well thought out, and seem like they do a lot of heavy lifting, so I'm not bashing the Infragistics controls in any way. I'm just not in a place yet to even get the full enterprise edition of VS, so I'm having to learn how to get along without the fancy bits like magic controls.
      Plus there are just situations that will simply require more than a built in solution. I want to learn how to make a control that will be tied to beginning and ending Gantt Chart dates, that align with the project goal or item or whatever on one side of the grid, then have the ability to stretch them back and forth across multiple days or weeks as needed, then have them "zoom in and out" , scaling back and forth for reflecting smaller or bigger time periods... that's.. not easy. lol. But I know it just takes going over the basics again of custom or user controls, whichever is better to start from, as Sean so marvelously helps with, and struggling until I do it right.

    • @ElCidPhysics90
      @ElCidPhysics90 Год назад

      I understand the desire to utilize something that is already built, like Prism. However, I’m always leery when relying on 3rd party software since you have to rely on the developers maintaining and keeping the code up to date.

  • @user-je2lx6lx3k
    @user-je2lx6lx3k 3 года назад

    how could you bind HomeView and HomeViewModel without set datacontext?

  • @damienkarkanica9242
    @damienkarkanica9242 2 года назад

    Having some trouble with your example here. I followed this specific tutorial to a key but am not able to get my views to update. Your Source code is most likely of the #2 piece of this and I am only interested in making the first part of this work for the time being. Not sure where my project is coming up short. Not sure what my options are to try to get some help from you if possible.

    • @SingletonSean
      @SingletonSean  2 года назад

      Hi Damien! Here is the state of the source code for after this video:
      github.com/SingletonSean/wpf-tutorials/tree/ed841f474a36d7621b2b87c5103bdc05c4d0248b/NavigationMVVM
      You can compare against this to see where your project is coming up short. If this doesn't help, feel free to link a repository with your source code and I will take a look!

    • @damienkarkanica9242
      @damienkarkanica9242 2 года назад

      @@SingletonSean OMG, thank you good sir. I will dig in on my own to see if I can find the issue. One thing to note ahead of time is the fact that I am re-writing your methods here in VB.Net so not sure if there might be something. I won't leave you hanging though and will follow up with what I find the issue to be. I am very new to programming in general (as my main focus has been SQL development), not to mention coding with the MVVM pattern. I truly appreciate this from you,

    • @damienkarkanica9242
      @damienkarkanica9242 2 года назад

      @@SingletonSean After digging I am still unsure of where my deficit is. I have trace my code all the way through the execution of the button click with _navigationStore.CurrentViewModel = _createViewModel() showing the correct new view model. It is like it isn't handling the Event correctly. That said I am very new to programming in general and I am not sure how to "link a repository with your source code". That said considering your example is in C#, not even sure if it is worth even doing that. I didn't get to pick the language I did this in.

    • @JuicySoup
      @JuicySoup 2 года назад

      Same issue here, I have followed the tutorial and have identical code but it is not handling the event correctly. Have tried to figure it out but can't find why its happening

    • @JuicySoup
      @JuicySoup 2 года назад

      Invited you to my github repo if you wanna have a look.

  • @alexcorsega6670
    @alexcorsega6670 2 года назад

    But why you didn't set the datacontext of your home or account.xaml?
    doe's wpf implicitly do it?

    • @SingletonSean
      @SingletonSean  2 года назад

      That's correct alex! WPF passes the DataContext down the tree of UI components implicitly.

  • @melonkami9850
    @melonkami9850 2 года назад

    What NUGet package is NavigationbarMVVM? I am so confused

  • @omerkorkut
    @omerkorkut 3 года назад

    thanks

  • @phil1105
    @phil1105 2 года назад

    Nice demo, clear and all. But this creates a memory leak for me. The more I navigate, the bigger the memory usage gets. Unless I missed something. And it is related to that event on your navigation store to notify the UI that the viewmodel changed. If I navigate with the event not subscribed the memory doesn't get bigger and bigger.

    • @SingletonSean
      @SingletonSean  2 года назад

      Hey Phil, interesting find! It would make sense for the memory usage to increase since we are creating new view models and UI elements each time we navigate.
      Before we classify this as leak, there's a few things to consider:
      1. The .NET garbage collector (GC) only runs under certain conditions: docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals#conditions-for-a-garbage-collection. In this case, the GC might not bother cleaning up the stale view models/UI elements since the system isn't under memory strain. To confirm this, you could do a GC.Collect() in the CurrentViewModel setter on the NavigationStore. I just did this myself, and I saw good results in my opinion!
      2. You might also see different memory usage characteristics when running in Release mode
      Let me know if these considerations soothe your concerns!

    • @phil1105
      @phil1105 2 года назад

      ​@@SingletonSean Hello, Thank you for taking the time to answer my concern.
      I'm not super knowledgeable in programming, that is why I watch your videos ;), but I just find it really strange that the memory usage just keep getting bigger and bigger and never stabilizes or go down even after many Garbage Coillection. We can see in VS when we debug, in the diagnostic tool, when the Garbage Collection occurs. Even if it does occur on its own our if I use GC.Collect() like you suggested(didn't know that thank you), the memory usage keeps getting bigger and bigger. I started at 64mb and went up to 500mb at which I stopped trying. That is a memory leak to my understanding...
      Then, as you said, running the app in release mode change the memory usage characteristics and fixes that. I started at 65mb and stabilize around 85mb. Then, when I continue to navigate it grow and shrink but stay around that amount.
      Long story short, thank you, I learned something. I didn't know that the memory behavior could be that much different in debug and in release.
      If you have an explanation or a link that explain why, it would be much appreciated for my knowledge.

  • @wojciechspirin4984
    @wojciechspirin4984 2 года назад

    The problem I have are two windows opening after debugging/compiling - one blank and the other one with correct view. Can anyone help me?

    • @SingletonSean
      @SingletonSean  2 года назад +1

      Try removing "StartupUri" from the App.XAML file :)

  • @kevinmungame1869
    @kevinmungame1869 3 года назад +1

    That's too much just for navigation, thanks for the video. I think wpf is complicated enough

  • @candinhosilveira2047
    @candinhosilveira2047 8 месяцев назад

    can anyone tell me why not use windows instead of usercontrols

  • @yyttommy2456
    @yyttommy2456 Год назад

    it's a little harder for me, but I know it's great!

  • @mariomorazan9473
    @mariomorazan9473 3 года назад

    Basicly is State Pattern and moderator.

  • @dawidblum8461
    @dawidblum8461 3 года назад

    Why would, make segment about seperate commands just to completly change that. It's really hard to follow the video if for example I want to go for one NavigateCommand instead of two

    • @SingletonSean
      @SingletonSean  3 года назад +1

      Thanks for the feedback Dawid. I prefer to walk through the steps I took to get to the solution rather than jump straight to the solution. Perhaps that was not applicable for this scenario.

    • @dawidblum8461
      @dawidblum8461 3 года назад

      @@SingletonSean I mean, everyone learns diffrently and it throws me off when i do sth just to change to other solution and when I debug it's hard to jump around the video with two solutions. Great that you're reading feedback.
      Ps. sorry if i sounded passive-agressive but I got irritated since i'm learing mvvm architecture and there are muliple ways of solution to one problem and mixing them is hard (for example ways to implement commands) In fact i'm really thankful for your videos, they provide lots of useful information and good example, just this one thing that makes it harder for me

    • @rickifunk51
      @rickifunk51 2 года назад

      @@dawidblum8461 Would you have implemented a generic command, if he didnt show it in the video? If your answer is no, then you just learned something from watching it. If your answer is yes, then you had no reason to follow along, when he first created two different commands.
      If he started out by making a generic command, would you understand why he did it, without the prior example?

    • @dawidblum8461
      @dawidblum8461 2 года назад

      @@rickifunk51 dude... I already answered him

  • @invesigativesource9832
    @invesigativesource9832 2 года назад +2

    Good information, but please slow down a bit. You tend to jump around very fast between your files and say something about it and then quickly jump to another file. Most of the time I'm not sure where you're jumping to before you jump to another file. Pausing between sentences would be beneficial for teaching.

  • @stagirit384
    @stagirit384 Год назад +1

    When application is starting there ain't DataContent

  • @hallen6582
    @hallen6582 5 месяцев назад

    sorry but i have to install something?

  • @prototype8861
    @prototype8861 8 месяцев назад

    MainViewModel inherits from a base class and also has a property of that base class within itself. Whut??
    Unnecessary pass through classes with extra complicated weird markup Microsoft hell for a simple navigation menu lol😂

  • @Maxmarcos84
    @Maxmarcos84 3 года назад

    My brain hurts...

    • @SingletonSean
      @SingletonSean  3 года назад +1

      Just another day in WPF land, haha.

  • @ProCook703
    @ProCook703 Год назад

    So blurry 😢

  • @majordan9747
    @majordan9747 2 года назад

    so fast

  • @tobiassjoholm9325
    @tobiassjoholm9325 2 месяца назад +1

    How to make navidation complicated...good presentation but i dont recommend coding like this, WPF has a lot of shit stuff that is over compliated for simple stuff

  • @horstschlemmer5092
    @horstschlemmer5092 2 года назад

    Dependencies all over the place. This is awful.

    • @Romahotmetytky
      @Romahotmetytky 2 года назад

      can you provide a link to a video where it's done best way possible ?