No video

Switching Between Multiple Views in MVVM - EASY WPF (.NET CORE)

  Рет қаралды 89,671

SingletonSean

SingletonSean

Күн бұрын

Learn how to switch between views/user controls when using MVVM architecture.
SOURCE CODE: github.com/SingletonSean/wpf-...
💎 Become a Member: / @singletonsean
🏠 Discord: / discord
🐤 Twitter: / singletonsean_
🏆 Donate: www.paypal.com/donate?hosted_...
✉️ Email: youtube@singletonsean.com

Пікірлер: 174
@SingletonSean
@SingletonSean 3 жыл бұрын
I strongly recommend checking out my series on navigation. Not only is the video quality much better, but the approach I use in that series is better-suited for larger applications, and I also cover other navigation scenarios. Link: kzbin.info/aero/PLA8ZIAm2I03ggP55JbLOrXl6puKw4rEb2
@omerbilalcan
@omerbilalcan 7 ай бұрын
Dear colleague, I developed to now web applications. But I didn't have any idea and it was different to understand before your tutorials. Now I am writing your codes line to line and trying to understand every points. Thank you so much about these resources.
@Psycho8Everything
@Psycho8Everything 2 жыл бұрын
This is a great resource on MVVM. At first I was using frames to attempt switching views but this is much simpler as well as trying to use pages instead of only UserControls, cheers for the tutorial. Saved me at least a week or so figuring this out!
@tatenda230788
@tatenda230788 4 жыл бұрын
This is a master piece code, explained in the most simplest form ....Thanks a lot from Zimbabwe
@SingletonSean
@SingletonSean 4 жыл бұрын
Thanks for watching Tatenda, glad you enjoyed!
@StepanUa7
@StepanUa7 3 жыл бұрын
this is now all tutorials should be done, great work dude
@theblackbaron4119
@theblackbaron4119 2 жыл бұрын
Thank you, that helped a lot. I did it a bit different with a switch case and even more strict separations/ abstractions and it worked :)
@mbjuggernaut
@mbjuggernaut 2 жыл бұрын
Thank you, highly helpful video (once I got that views here are usercontrols, not pages). Very understandable, very pleasant manner of explaining.
@abdelhalimfellague_chebra9338
@abdelhalimfellague_chebra9338 4 жыл бұрын
well, this is the best video explaining navigation using MVVM so far, easy and simple, thank you verry much sir, you should keep doing this, nice work
@SingletonSean
@SingletonSean 4 жыл бұрын
Thank you abdelhalim, glad you enjoyed!
@lucckyboy713
@lucckyboy713 4 жыл бұрын
Thank you so much. Your video makes it very clear how MVVM works. Thanks again. Hi from Belarus. 10 / 10.
@SingletonSean
@SingletonSean 4 жыл бұрын
No problem Виктор, I'm glad you were able to solve your issues with the namespace. Trying a rebuild was a good idea. I'll suggest that next time someone has namespace issues, thanks!
@Freakhealer
@Freakhealer 3 жыл бұрын
Notice that you need to Add UserControl(WPF) for the Home and Account Views. I was struggling with that since I created Page(WPF) But great Tutorial very helpful, thanks.
@orlandoreyes884
@orlandoreyes884 2 жыл бұрын
Excellent!! This what I have been trying to do. Thank you.
@oualidberrim5218
@oualidberrim5218 2 жыл бұрын
You are amazing.. This is the best informative series of videos on KZbin.
@SingletonSean
@SingletonSean 2 жыл бұрын
Thanks Oualid, that means a lot! I'm glad these vids are helpful
@ryanrobbins4391
@ryanrobbins4391 3 жыл бұрын
saved my life. thanks for this awesome video!
@shvideo1
@shvideo1 18 күн бұрын
Excellent video. Thank you for sharing this very important concept.
@maikborchardt5692
@maikborchardt5692 3 жыл бұрын
love your work! thanks for your effort.
@shahjahan12003
@shahjahan12003 3 жыл бұрын
Awesome tutorial!
@bartomiejciurla8472
@bartomiejciurla8472 3 ай бұрын
Very usefull video! Thanks a lot!
@firewalker1606
@firewalker1606 3 жыл бұрын
Nice video! It is that i loocked for!
@mr.paanaa3765
@mr.paanaa3765 3 жыл бұрын
thank you, sir. simple and powerful code
@DatMight
@DatMight 3 жыл бұрын
Hello, how would you go about implementing this and then giving the ability to change the view depending on clicking/mousedown an element inside the ContentControl?
@ElCidPhysics90
@ElCidPhysics90 2 жыл бұрын
Your channel is way underrated.
@SingletonSean
@SingletonSean 2 жыл бұрын
Thanks ElCidPhysics!!
@ElCidPhysics90
@ElCidPhysics90 2 жыл бұрын
@@SingletonSean You're welcome.
@rohitgalgali5512
@rohitgalgali5512 2 жыл бұрын
Thank you very much for the video! :)
@tpops2697
@tpops2697 4 жыл бұрын
I'm making an app that has a dashboard as the home screen, I want that to show at startup, so should I even have a dashboard view and just design that on the mainwindow?
@Danger418
@Danger418 4 жыл бұрын
Good tutorial, thanks!
@SingletonSean
@SingletonSean 4 жыл бұрын
Thanks Danger418, glad you enjoyed it!
@parko1965
@parko1965 3 жыл бұрын
@SingletonSean just out of curiosity are you using the WPF Core templates for these tutorials?
@sometexthere4169
@sometexthere4169 3 жыл бұрын
Hello! Thank you for what you doing! I have a question. As programmer i always hate to repeat similiar code. For me "DataTemplate" block is excess. Is any opportunity to bind view and viewModel automatically? Like if i have HomeViewModel - so i need just HomeView. Thats it. Any suggestions?
@mehdizeynalov1062
@mehdizeynalov1062 2 жыл бұрын
Excellent tutorial - i have watched videos of tim corey - you can expect 20 minutes of this video more valuable than 20 hours of tim's.
@SingletonSean
@SingletonSean 2 жыл бұрын
Thanks Mehdi! I do prefer to keep my content short and concise. Tim's content is great too!
@mehdizeynalov1062
@mehdizeynalov1062 2 жыл бұрын
@@SingletonSean Thank you by no means I didn't want to tell bad about Tim, and should spent 20 years before I can do so... on the other hand, your videos are really great. just the thing i wanted to mention is as always popular doesn't mean good... I just found your videos totally by chance... On the other hand wish your videos to gain deserver popularity soon...
@user-bi1ll1wy2m
@user-bi1ll1wy2m 2 жыл бұрын
nice thank you :)
@notlegal99
@notlegal99 3 жыл бұрын
you are my god
@idnafu
@idnafu 3 жыл бұрын
Really nice tutorial and i was able to build the demo but now i have a strange issue. If i have a button in the MainWindow it works correctly. But if the button is on the Usercontrol that i loaded the ContentControl does not get updated even though the Updateviewcommand is fired and viewmodel.SelectedViewModel is set Any idea why that is?
@noahyannis2465
@noahyannis2465 2 жыл бұрын
But if the DataContext is set to the MainViewModel, how do I let my views access my other view models? Because otherwise, it seems I have to cramp everything into one MainViewModel.
@recepcakir4866
@recepcakir4866 Жыл бұрын
Great tutorial!! Just have a question about stackpanel, I've put the buttons at the top of the window and I want the loaded page data to be displayed right below the buttons, how can I accomplish this?
@theway5258
@theway5258 4 жыл бұрын
Thanks. man!
@_SkyDancer
@_SkyDancer 2 жыл бұрын
7:14 So you always create new objects on command execution, I gues it is better to check if model is null then create one and store or smth like this, or I'm wrong?
@_samirdahal
@_samirdahal 4 жыл бұрын
Okay so I am having a funny issue now. It used to work from App.xaml . Now when I bind to a new instance to the 's Content property I can't open the respective views. But when I add
@M4RKU5H
@M4RKU5H 3 жыл бұрын
thanks, great starting point, but what if i only want to switch between the views and not having a new instance every time i switch?
@niklas6143
@niklas6143 3 жыл бұрын
I got the error "The event "UpdateViewCommand.CanExecuteChanged" is never used. I just copied your project and added/renamed the views and viewmodels. Can someone help?
@Freakhealer
@Freakhealer 3 жыл бұрын
@SingletonSean if I want instead of the main page button use a link inside the Home what do I need to do ? at the moment I have both and mainpage btn works but on the link says on console that cant find the file
@Freakhealer
@Freakhealer 3 жыл бұрын
I found the answer have to look for ancestors
@bigayysfromspace2804
@bigayysfromspace2804 Жыл бұрын
I want buttons on my child views to switch contexts, but I wasn't able to get that to work. I tried putting the thing that stores the UpdateViewCommand function in the parent class and have the child view models inherit it, but that doesn't work. What should I do to achieve this objective? EDIT: when binding a function to a button, I have to bind the name that the viewmodel gave it, not the name of the class itself.
@bigayysfromspace2804
@bigayysfromspace2804 Жыл бұрын
Honestly a lifesaver. Problem is, build order stings a bit. If I wanted to add more views I need to change the csproj or remember to build before altering the App.xaml file.
@Inzurrekto1
@Inzurrekto1 4 жыл бұрын
Thank you so much bro!
@SingletonSean
@SingletonSean 4 жыл бұрын
Thanks for watching Nicolás!
@Inzurrekto1
@Inzurrekto1 4 жыл бұрын
@@SingletonSean Hey, I have a question. How I can switch panels but with a single instance of each one?
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey Nicolás, great question. I actually get that question a lot, so I ended up making a demo last time someone asked. Take a look at this: github.com/SingletonSean/SimpleTrader/commit/428c6de1c52e4973495dc8ab4837a839050c886c The main idea is that you store the view model in a field and set the SelectedViewModel to the view model in the field whenever you want to switch back to the view. Let me know if you have any issues :)
@SoferPeOZN
@SoferPeOZN 3 жыл бұрын
I like it but it does not work when I try to change the SelectedViewModel within another view =(
@mrcoolandroid
@mrcoolandroid Жыл бұрын
Hello, i find your videos really helpful but i have a question, how would I go if i want to change the view from another ViewModel?
@majordan9747
@majordan9747 4 жыл бұрын
Hello, thanks for your video. What does the DataTemplate have to be built?
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey Ma Jordan, thanks for watching! The DataTemplate tells WPF what to display for a certain type. For example, at 2:27 we create a ContentControl and set the Content property to our SelectedViewModel. At 4:05, I use a DateTemplate to basically tell WPF that HomeViewModels should be displayed as HomeViews. As a result, when the type of the Content property on the ContentControl is a HomeViewModel, the ContentControl will display a HomeView.
@KaloyCoder
@KaloyCoder 4 жыл бұрын
hi do you have a github repo for this demo?
@FuzzyDPozzy
@FuzzyDPozzy 3 жыл бұрын
what does the DataTemplate do?
@tpops2697
@tpops2697 4 жыл бұрын
What if i wanted to open another view within a view? For instance, on my dashboard I have a customers tab. I click that and im taken to a view where the datagrid of customers is shown. But i want to have a button on that page that displays a new view for me to add a customer.
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey T Pops, that's a great question. It seems like your application has some pretty advanced navigation. For advanced navigation in WPF, I would recommend wrapping your "SelectedViewModel" in a class, such as "Navigator". Then, I would bind your ContentControl on the MainWindow to the Navigator.SelectedViewModel. Now that your SelectedViewModel is in it's own class (Navigator), you could pass your Navigator through the constructor of your other view models (such as your CustomerViewModel). Then, in your CustomerViewModel, you could use the Navigator and change the SelectedViewModel to whatever you want (such as NewCustomerViewModel). In my Full Stack WPF MVVM series, I demonstrate wrapping the SelectedViewModel in it's own Navigator class. This video focused on simple navigation, so perhaps I will dedicate a video to advanced navigation and demonstrate what you are trying to accomplish. Thanks for the idea! I apologize if my written description didn't help, but keep an eye out for a video in the future.
@tpops2697
@tpops2697 4 жыл бұрын
SingletonSean Thank you!
@r.o.9322
@r.o.9322 3 жыл бұрын
@@SingletonSean Did you manage to upload that video? It would be helpful! Thank you:)
@iftaker1
@iftaker1 3 жыл бұрын
Thanks for the video, very simple and straightforward to understand. However I was wondering why didn't you use pages instead of user control for views? Is there any special considerations while using pages instead of user control?
@SingletonSean
@SingletonSean 3 жыл бұрын
Hey Iftaker, that's a great question. Pages are most beneficial along with NavigationWindows. Since I typically just use a plain Window, I almost always use UserControls. EDIT: In fact, here's a good SO comment that talks about Window vs. Page vs. UserControl: stackoverflow.com/a/20292416
@rafaspimenta
@rafaspimenta 4 жыл бұрын
Good teacher! bty, do you use Caliburn in bigger apps?
@SingletonSean
@SingletonSean 4 жыл бұрын
Thanks Rafael! Many people ask about my experiences with WPF frameworks. I haven't used Caliburn before on a large app, but I have played around with it and browsed through the docs. I'm not a big fan of the framework's conventions, and I also noticed the project is no longer under maintenance. I feel more comfortable using WPF without a framework. I've read many varying opinions on WPF frameworks, so I don't think there's any right or wrong option.
@Speede04
@Speede04 2 жыл бұрын
What if my viewmodels already inherit from another class?/ I can not implement BaseViewModel to them :(
@crazydreamer2324
@crazydreamer2324 3 жыл бұрын
Hello I tried in my mvvm project..but command is not getting fired from mainwindow though I given proper command and it's parameter...even debugger is not coming when I click home or account
@yanzhainie484
@yanzhainie484 4 жыл бұрын
Hello, your video is great help for me to learn wpf. Hope some mvvm framework videos,such as mvvmcross or prism. Thanks
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey Yanzhai, glad the video helped. Personally, I have never felt the need for an MVVM framework as I feel WPF has good support for MVVM, but many people have requested I try out a framework. I always feel like I learn something useful from trying frameworks, so I might take a look.
@davidporterrealestate
@davidporterrealestate 4 жыл бұрын
@@SingletonSean Take a look at ReactiveUI
@sajadmalik9097
@sajadmalik9097 3 жыл бұрын
how am i going to put material design theme resources and data templates together ....i get errror
@lmao01
@lmao01 3 жыл бұрын
tyty
@linuslindstedt4065
@linuslindstedt4065 2 жыл бұрын
What WPF version are you doing?
@seemovielove3597
@seemovielove3597 4 жыл бұрын
I barely see your screen. could you post some source code? thanks
@limbique
@limbique 2 жыл бұрын
Does it mean that for each new type of viewmodel, you need to alter the app.xaml?
@SingletonSean
@SingletonSean 2 жыл бұрын
That is true Limbique. You would also extract all the viewmodel-to-view mappings to their own ResourceDictionary so that they are easier to find. Then you'd just need to import the ResourceDictionary into the App.xaml. I usually do this whenever I have a ton of views/view models.
@ElCidPhysics90
@ElCidPhysics90 Жыл бұрын
Does MainViewModel need to be a viewmodel? Could it be just be just a c# class with a field or property that is the selectedViewModel?
@SingletonSean
@SingletonSean Жыл бұрын
Hi ElCidPhysics! The MainViewModel will indeed need to be a view model (implement INotifyPropertyChanged) since we bind to it from the view. Without implementing INotifyPropertyChanged, the view would not update when we switch views. There's also been discussion that binding to an object that doesn't implement INotifyPropertyChanged could cause memory leaks, but I've never seen it first-hand.
@ElCidPhysics90
@ElCidPhysics90 Жыл бұрын
@@SingletonSean awesome. Thanks for the explanation. Learning WPF has been a struggle. I get WinForm, .Net, even Blazor to an extent. Bug fir whatever reason I’m struggling with WPF. Thanks for your videos.
@SingletonSean
@SingletonSean Жыл бұрын
No worries, it is certainly notorious for having a steeper learning curve 😅
@tungtran5305
@tungtran5305 2 жыл бұрын
At 3:50, i have no DataContext found for SelectedViewModel, can anyone help me w this? Much apperciate.
@karajkot6735
@karajkot6735 4 жыл бұрын
Github link if possible. I think I am doing something wrong in views folder content
@robertenglund3578
@robertenglund3578 4 жыл бұрын
Gives an error in the App.xaml file at saying - " The HomeViewModel does not exist in the namespace " clr-namespace:MMVMTesting2.ViewModels ". Any idea if what would cause this Error?
@robertenglund3578
@robertenglund3578 4 жыл бұрын
Nevermind, just needed to Build the application and the issue was resolved
@SingletonSean
@SingletonSean 4 жыл бұрын
Awesome Robert, way to persevere through your issues!
@pepeArz
@pepeArz 3 жыл бұрын
I know this is easy, but, how can I show one of this pages at the start of the application?
@rcs368
@rcs368 4 жыл бұрын
I like what you are doing here, any chance you could zoom in a little, or increase your font size in the editor for video purpose?
@SingletonSean
@SingletonSean 4 жыл бұрын
Thanks rcs368, I had another viewer suggest I increase the font size as well. If you look at my recent videos, they should have larger fonts, but let me know if the font size still is too small. I apologize for the small fonts on my older videos, I was a rookie lol.
@rcs368
@rcs368 4 жыл бұрын
@@SingletonSean I noticed on the next video I watched the font size was MUCH better. Thanks
@SingletonSean
@SingletonSean 4 жыл бұрын
Great! Thanks for the feedback.
@douglasbates389
@douglasbates389 4 жыл бұрын
Sorry did not leave a contact Hello, I found your video very useful. How could I change the button(s) and put a treeview control in place to change the views. Also in the TreeView I would like to have a just one known Parent Node (by Name) have a contextmenu that adds a child. Then in the Child Nodes of this particular Parent Node have a different ContextMenu that has two options Rename and Delete. One thing to note with the known Parent Node is that the Child Node(s) all use the same view and only the data changes. The structure would be:- +Root +Parent1 Child1 {view UserControl1} Child2 {view UserControl2} +Parent2 Child1 {view UserControl3} Child2 {view UserControl4} +ParentX {ContextMenu(P) - Add Child} ChildX1 {ContextMenu(C) - Rename Child, Delete Child} {view UserControlX} ChildX2 {ContextMenu(C) - Rename Child, Delete Child} {view UserControlX} ChildX3 {ContextMenu(C) - Rename Child, Delete Child} {view UserControlX} +Parent3 Child1 Child2 Can you help me please or point me in the correct direction. Bates.JamesDouglas@gmail.com Show less
@ijazalishah1908
@ijazalishah1908 4 жыл бұрын
Hi, I found the following error, System.Windows.Markup.XamlParseException: 'Window must be the root of the tree. Cannot add Window as a child of Visual.'
@andreisirbu3012
@andreisirbu3012 4 жыл бұрын
Same ...
@crtvben3714
@crtvben3714 4 жыл бұрын
Your views have to be of type "User Control", not "Window"!
@solvedplus858
@solvedplus858 2 жыл бұрын
this is great many thanks can you show us how to use enum in commandparameters instead of normal text how to open new window and collect data from it using MVVM thanks in advance
@leek2436
@leek2436 Жыл бұрын
How can i display a usercontrol by clicking a button in another usercontrol ?
@yasirali9190
@yasirali9190 2 жыл бұрын
I have a problem of data lost in views when i switch views then views can't hold data
@user-vg1ft2qf5i
@user-vg1ft2qf5i Жыл бұрын
Great tutorial. It's only 50% of my problem. How do you pass data objects from MainViewModel to the new view ?
@rain2223
@rain2223 4 жыл бұрын
Hey, when I press a button nothing happens, and this is in my output: System.Windows.Data Error: 40 : BindingExpression path error: 'UpdateViewCommand' property not found on 'object' ''Login1ViewModel' (HashCode=31450711)'. BindingExpression:Path=UpdateViewCommand; DataItem='Login1ViewModel' (HashCode=31450711); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand') How can I fix this? Basically, I did the same thing as you, except that my button is not in MainWindow, but in Login1View instead.
@SingletonSean
@SingletonSean 4 жыл бұрын
Hi Rain, the issue is that your DataContext for your button is the Login1ViewModel. Therefore, your UpdateViewCommand will need to be on your Login1ViewModel as well. Otherwise, your button will be unable to find the command. It seems that you are attempting to navigate to a different view from within another view, correct? I have many people asking about this, so perhaps I will make a video on solving this navigation case.
@rain2223
@rain2223 4 жыл бұрын
@@SingletonSean Yes, that is what I'm trying to do. A video would be great :)
@rain2223
@rain2223 4 жыл бұрын
@@SingletonSean Still haven't managed to fix it :( Do you perhaps have an example of this somewhere? I'm getting some weird errors and I don't even know where to begin debugging it.
@noahyannis2465
@noahyannis2465 2 жыл бұрын
@@rain2223 could you fix it now?
@7oussemTube
@7oussemTube 2 жыл бұрын
I'm looking for tutorial like this for a while. I just want to ask you how can I build the same project using .Net Framework (Not .Net core)? and how to use MVVM inside my current project(I'm using .Net Framwork 4.6) ?...Thank you bro in advance.
@ritamgiri5872
@ritamgiri5872 Жыл бұрын
Hi @SingletonSean I just started learning WPF. I was working on a personal project. I want to use two commands in a SIngle ViewModel. Can you suggest me how I do that or refer me a video?
@SingletonSean
@SingletonSean Жыл бұрын
Yes Ritam! I discuss this topic in this video (at around the 7:05 mark): kzbin.info/www/bejne/mIqzhmuObctlrrc
@ritamgiri5872
@ritamgiri5872 Жыл бұрын
Thank you very much.
@Dayzito
@Dayzito 4 жыл бұрын
Thanks for creating this tutorial =) Do you have an example sharing property among ViewModels, for instance,, ListView => DetailsView
@SingletonSean
@SingletonSean 4 жыл бұрын
Thanks for watching Day! Unfortunately, I don't have a specific video on this, but have this in the plans for a really awesome series. I think what you might be looking for is the concept of a "store". The store holds shared application state, and then the view models use the store to grab the shared data. This is inspired by the "mediator" design pattern. I think my best example is in my SimpleTrader application, specifically with these files: AssetStore (shared properties) github.com/SingletonSean/SimpleTrader/blob/master/SimpleTrader/SimpleTrader.WPF/State/Assets/AssetStore.cs AssetSummaryViewModel (uses AssetStore for shared properties) github.com/SingletonSean/SimpleTrader/blob/master/SimpleTrader/SimpleTrader.WPF/ViewModels/AssetSummaryViewModel.cs
@tacci2568
@tacci2568 3 жыл бұрын
nameof() doesnt work for me working with visuals stuido 2013, same goes for ProperyChange?.Invoke
@SingletonSean
@SingletonSean 3 жыл бұрын
That's correct Tacci, those are new VS features. I used to always have to work in VS 2013 in legacy projects :( If you're unsure, the alternative to nameof() is simply the name of the property as a string. The alternative to PropertyChanged?.Invoke is to null check PropertyChanged, and then call PropertyChanged like a method. Thanks for watching!
@tacci2568
@tacci2568 3 жыл бұрын
@@SingletonSean ye i already found out, but my view is still not changing, even tho my button is working , perhaps its because i binded the SelectedViewmodel as ContentControl on the main window, but i cant bind it as Content Control on my user COntrol
@alvinyanson
@alvinyanson 2 жыл бұрын
Bro I'm not yet done with the whole video but I know that this is exactly what I was looking for. This is the very basic that I need to continue your SimpleTrader playlist currently on part 10 but I need to go back to get the basic understood well. PS. The financialprep api for ticker price cannot be accessed anymore if you are not a premium member. I'm having a hard time how to catch up with your tutorial if some of the api endpoints cannot be accessed anymore.
@SingletonSean
@SingletonSean 2 жыл бұрын
Glad this is helpful Alvin! As for the SimpleTrader playlist, sadly there's not much we can do about the API being premium only now. However, I'd recommend checking out this tutorial! kzbin.info/aero/PLA8ZIAm2I03hS41Fy4vFpRw8AdYNBXmNm It's much more concise and covers WPF features better imo.
@alvinyanson
@alvinyanson 2 жыл бұрын
​@@SingletonSean Thank you for the recommendation. This would be a perfect time to spend my weekend watching and learning from this playlist you provided. So far you both Tim Corey and You are the real OG of C# for me not joking 😤
@knowledgesharer6983
@knowledgesharer6983 Жыл бұрын
Anyone can tell me how command in Views knows about the ViewModel?
@jwvisions
@jwvisions 4 жыл бұрын
How are you doing this without a page in a frame? I followed word for word, even paused to make sure our code was the same, but it keeps yelling at me that a page must be part of a frame when I try to run.
@jwvisions
@jwvisions 4 жыл бұрын
Never mind. I believe I discovered they are UserControls, not pages. Good tutorial to show the MVVM framework.
@SingletonSean
@SingletonSean 4 жыл бұрын
Beat me to it! That's correct, UserControls instead of Pages. Great job exploring and solving the problem on your own. Thanks for watching Jesse, glad the video helped.
@TheSoulT
@TheSoulT 2 жыл бұрын
Nice Video, thank you. Can you explain how i can highlight the button of the active page? Would be very helpful. Thanks :)
@AlexHuang226
@AlexHuang226 2 жыл бұрын
After I tried the code, I found every time when I clicked the button, it will create another instances. That means if I click 10 times Home or Account button, it will create 10 instances of Home view and Account view. Did I miss anything?
@SingletonSean
@SingletonSean 2 жыл бұрын
That is correct Alex! The garbage collector will cleanup the previous 9 instances of views/view models, so no need to worry about memory leaks.
@AlexHuang226
@AlexHuang226 2 жыл бұрын
@@SingletonSean Thanks for your reply. :)
@mekkelek8190
@mekkelek8190 2 жыл бұрын
It is a great tutorial but for me the previous View does not disappears on the button click it puts the new content on top of the other I'm sure I missed something but can't find what 😵‍💫
@masturbek92
@masturbek92 4 жыл бұрын
Download link pls
@shritishaw8617
@shritishaw8617 3 жыл бұрын
can you share the code
@basharfocke
@basharfocke 7 ай бұрын
I am the like 1001
@lucckyboy713
@lucckyboy713 4 жыл бұрын
Why write "The type views:HomeView was not found "?
@SingletonSean
@SingletonSean 4 жыл бұрын
Did you import the views namespace into your App.xaml? Is your HomeView in the namespace "views"? If you post a link to your code, I will be able to diagnose the issue.
@lucckyboy713
@lucckyboy713 4 жыл бұрын
@@SingletonSean Thank you ) I resolved it . Just re-build)
@XPWHACTL
@XPWHACTL 4 жыл бұрын
I've tried this method and I'm not getting anything showing where the view should be :/
@SingletonSean
@SingletonSean 4 жыл бұрын
Hello David, I will be able to solve your issue if you provide source code. However, are there any errors in the output window when debugging? Did you map your views to view models in your App.xaml? Is anything being displayed on the screen (such as the names of the view model classes)?
@XPWHACTL
@XPWHACTL 4 жыл бұрын
@@SingletonSean I've completely recreated the project practically ad verbatum and I see no errors and nothing displayed on the screen.
@SingletonSean
@SingletonSean 4 жыл бұрын
I would love to help, but I cannot give suggestions or feedback without seeing your current project.
@XPWHACTL
@XPWHACTL 4 жыл бұрын
@@SingletonSean www.sendspace.com/file/q3boey Here is the project. I would much appreciate it if you could take a look.
@CH-mk1dh
@CH-mk1dh 4 жыл бұрын
Hello, You have to to the following Things: - in our MainWindow.xaml.cs File you have to add "DataContext = new MainViewModel();" in your Constructor - your AView.xaml.cs and BView.xaml.cs Files are missing sorry for my bad English :)
@yanchuntang7750
@yanchuntang7750 Жыл бұрын
can you make screen bigger, the font size is too small to read. any way good video
@tpops2697
@tpops2697 4 жыл бұрын
Let's say you wanted your home view to show at startup, how would that work?
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey Tanner, have you tried simply executing the UpdateViewCommand from your MainViewModel constructor?
@tpops2697
@tpops2697 4 жыл бұрын
@@SingletonSean Yes. this (gyazo.com/6fa4296371a2323aad0425d9e5a602af) is my MainWindow at launch. When I start the app, I would like for the Dashboard View to be shown by default where the white space is. I have already set that area of the screen for the content control, I'm just wondering how to display this particular View by default without having to click the Button for it after startup. (highlight link and copy, clicking doesnt show image). Thanks for the help!
@SingletonSean
@SingletonSean 4 жыл бұрын
Does the UpdateViewCommand execute from your constructor? Have you tried walking through/debugging with breakpoints and seeing if the SelectedViewModel is being set?
@Freakhealer
@Freakhealer 3 жыл бұрын
@@tpops2697 try add back the "new HomeViewModel(); in the MainViewModel
@BloodyClash
@BloodyClash 2 жыл бұрын
Problem ist that this doesn't work in .Net Core for any reason (no problem in .Net Framework). Edit: It DOES work in .Net when you switch the core version from 6.0 to 5.0 (and then back to 6.0). Maybe it's one of the Visual Studio's hiccups
@shantunusaha
@shantunusaha 4 жыл бұрын
It will be better if you share your source code also.
@daniyalihsan4264
@daniyalihsan4264 3 жыл бұрын
Sir kindly make sure that you zoom in while delivering lecture rest is good.
@SingletonSean
@SingletonSean 3 жыл бұрын
This was my first video ever (as you can probably tell by the quality hahaha). My newer videos have much better quality. Thanks for watching, Daniyal!
@crazydreamer2324
@crazydreamer2324 3 жыл бұрын
Please suggest @singleton sean
@downware2149
@downware2149 2 жыл бұрын
you should try to make videos when you are sober 😄
@SingletonSean
@SingletonSean 2 жыл бұрын
I'll consider it! 😄
@angelbarrantes3226
@angelbarrantes3226 Жыл бұрын
if this helps me, i will give an star on github 🙂
@afterbunny257
@afterbunny257 4 жыл бұрын
public void OnPropertyChanged([CallerMemberName] string propertyName = null){ ... } can save your time typing the prop name
@SingletonSean
@SingletonSean 4 жыл бұрын
I like using CallerMemberName, but some projects I work in don't use it :( so I just always pass in the property name as a habit in case the project doesn't use CallerMemberName. Plus, I created a snippet that generates all the code for an OnPropertyChanged property, so it doesn't bug me much. For personal projects I should just use it though lol. Thanks for the suggestion Afterbunny!
@dsacppracticequestion1123
@dsacppracticequestion1123 Жыл бұрын
Please try to make the fonts little bigger, very hard to see the text.
@SingletonSean
@SingletonSean Жыл бұрын
Hey DsaCpPractice, my videos have much better font size nowadays. This was actually my very first video!
@MaikeLDave
@MaikeLDave 3 жыл бұрын
Easy xD
@SingletonSean
@SingletonSean 3 жыл бұрын
Easy WPF!
@kumarrishabh3587
@kumarrishabh3587 3 жыл бұрын
please increase the font size
@SingletonSean
@SingletonSean 3 жыл бұрын
Hey kumar, my newer videos have the increased font size. Check out this series if you want to see navigation videos with increased font size :) kzbin.info/aero/PLA8ZIAm2I03ggP55JbLOrXl6puKw4rEb2
@mb-ql1gb
@mb-ql1gb 4 жыл бұрын
Very complicated and much code only for changing content. Why not making CunstomControls as Form and exchange them in DataContext on Mainform? That also needs no PropertyChanged for Mainform.
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey mb, thanks for watching and glad to hear you enjoyed the video. This is WPF, so unfortunately I'm not sure what you mean by form. I also prefer keeping my navigation in the view model so I can navigate from inside a view model whenever I need to. However, I'm always interested in seeing other people's ideas in action, so it would be awesome if you linked to an implementation of your solution if possible.
@mb-ql1gb
@mb-ql1gb 4 жыл бұрын
@@SingletonSean This is what I hate about WPF, much code for less things. But I must excuse myself, watching it on 2 times speed was too fast. You did it right and in correct way. Maybe you can save the ICommand by using code-behind with that click-event. But as always there are hundreds ways to solve a problem. Also I never used a Property-Changed-Event for that, reassigning the data-context did an update by itself, if I remember right. With "Mainform" I ment MainWindow., you also still used a UserControl, so please excuse my mistake. But otherwise a very good tutorial and very good explained! I myself experimented with a more crazy way, I made every model-view static and let them handle his Window by itself. Exchanging data between different view is easy that way, but it takes a little bit of that separation between UI and Code, but for most applications a correct done MVVM is way to much work to implement, so I tried a way between.
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey mb, thanks for the feedback, I love discussing solutions and those are good points. I agree, could save an ICommand implementation or even use the "RelayCommand" that everyone seems to love, but like you said hundreds of ways to solve a problem, hahaha. Anyways, you're definitely right that it does take a lot of code to do some things in WPF, and making that choice really depends on the scope of your project. Like you suggested, many simple projects probably don't need to spend time implementing a pure MVVM solution. I'm sure you're not the only one who thinks this takes too much code, so I would like to revisit my implementation and see if I could simplify the solution. I've explored a lot with navigation since I made this video.
@ironside915
@ironside915 4 жыл бұрын
Terrible. I got lost within minutes even tho I tried super hard...
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey Ironside, be sure to subscribe and check out my other videos for more help on getting started with WPF.
Async Commands (and Async Relay Command) - EASY WPF (.NET CORE)
14:14
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 118 МЛН
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,5 МЛН
لااا! هذه البرتقالة مزعجة جدًا #قصير
00:15
One More Arabic
Рет қаралды 13 МЛН
Why Is He Unhappy…?
00:26
Alan Chikin Chow
Рет қаралды 68 МЛН
C# WPF Tutorial - Multiple Views
20:00
ToskersCorner
Рет қаралды 166 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 118 М.
Creating Reusable Controls - WPF TUTORIALS
17:10
SingletonSean
Рет қаралды 30 М.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 36 М.
Handling WPF Routed Events with MVVM Commands - EASY WPF (.NET Core)
10:54
how Google writes gorgeous C++
7:40
Low Level Learning
Рет қаралды 839 М.
C# WPF and GUI - Pages and Navigation
7:48
Ilford Grammar School
Рет қаралды 280 М.
How much does the Windows Community MVVM Toolkit REALLY help us?
7:02
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 118 МЛН