Good video. The only thing about mvvm I don't like is sometimes all of the additional classes and code compared to regular code behind can actually makes your code base more convoluted.
Thank you for the video. Your video is very helpful but there is two things that i wanted to point out. 1-) You placed the logic on ViewModel, which shouldnt have any logic inside. 2-) By connecting the View model with logic inside to the xml, you have done nothing but pointing code behind(MainForm.cs) to ViewModel.cs. Thank you again for your time and efford.
My question is how is it knowing that it has to execute that command on Click only. Why not on hover or anything else. We have not mentioned click anywhere??? Please help.
I don't understand your example with print command. Why should we write the code with codebehind page three times. I don't think anyone is doing it. You just write once a print function and just call it three times in the events in the code behind page. By using commands you also have to call the command three times, just not in the code behind page but in the binding of the view. Correct me if you have another opinion
I have a generic command that I've been using for years, which looks almost the same as yours. I wonder why Microsoft doesn't deliver this implementation instead of simply providing ICommand without any standard implementation.
This is a good example to illustrate my hesitation while I'm learning C# and .NET in general: I can see the author simplified the example to the best level possible, but I still can not comprehend as a generally logically thinking human beeing - why the hell the authors of this computer language made it so that to implement a simple thing one would reasonably hope to have done in a few lines of code and in just a few property settings hwere needed, it requires tens of lines of code, a number of entities and multi-level representation of the logically same thing (with repetition of entities like onion layers) ?? whose sick mind could invent such a programming philosophy I keep wondering? To me its an ideal source of many mistakes and bugs a general piece of SW is notorious with, or when finally bug-fixed and tested ok than explains why it costs so much to develop software (when another programmer struggles to understand what the author meant to do here and there if not properly commented in the code or without documentation). Doesn't the general science rule (citation from Einstein or someone else?) state that the right thing should be short and clear. To me the code should better be longer in terms of lines but more humanly understandable, to hell with these multiple layers of abstraction:)) Or what is this, a conspiracy? - make it difficult to understand for others and profit from your competitive advantage - artificially created logical constructs? :))
It's not to make things harder. It's used to decouple UI from the business logic. And though for this easy MessageBox.Show he has so much overhead in this example, the overhead is static here. He will be able to reuse that (Relay)Command class (and possibly ViewModelBase class). It's a lot of overhead for a simple and small WPF application, but it's the opposite when the application comes enormous and you want to couple your logic to a different UI. The MVVM design pattern is honestly not that complicated, though i think the documentation of it by many people seems disorganised. Once you understand that INotifyPropertyChanged is simply an event in the Setter methods of properties that helps UI to know when to re-get the value of that property after it has been set to something else and that commands are really just a public delegate void (object) that you pass a function into and can call from your UI using
Thank you very much for your video, I have one question please , till now I can’t understand that, your command has als default Click event , can I build command working with other events? For example hover or any other event? Thank you so much
Thanks for the wonderful video, I understood MVVM concept and I did practical as well, my both class files are as like yours still, I am getting the error that my namespace does not find the class. i tried to solve several ways have not got any luck . would you please suggest any solution to cure this problem !!!
You can set the Datacontext of the window from the UI using If you have your viewmodel in a folder then you could create a new xml namespace: xmlns:nameofchoice="clr-namespace:SolutionName.FolderName"
I just don't get commands, especially the claim that there is no code behind, and then proceed to write 2 full classes of code behind. So event = Add message box. And command = walk a mile and then add message box.
You are right in this simple case it's easier and quicker to write it into the CodeBehind of the View. But we are working towards understanding and using the MVVM pattern which is fundamentally the separation of the Business Logic code and the UI code. Perhaps you should re-watch the "MVVM Pattern in WPF" video again for the explanation of why we want to do this.
public ClickViewModel() { MyCommand = new OnclickCommand(ExecuteMethod, canExecuteMethod); } This, above parameter value pass error , how to resolve problem
I feel that it is the best video to learn that explains the Commands in WPF. Thank you very much, Sir 🙏
sometimes you're speaking too quickly, but I like how well organised is your speech here. Thank you for good explanation
Crystal clear! Thumbs up for this short clip.
Good video.
The only thing about mvvm I don't like is sometimes all of the additional classes and code compared to regular code behind can actually makes your code base more convoluted.
A best tutorial on RUclips on WPF. Please do add videos on concepts like how to implement icons, item templates, scrolling and adding behaviors etc.
Very well organised and simple to understand
Extremely helpful videos. Thank You Sir!
Helped me alot to understand basic,
than you so much.
Thanks for uploading this video. I recreated all your steps in Visual Studio 2019 Community Edition successfully.
Thank you for the video. Your video is very helpful but there is two things that i wanted to point out. 1-) You placed the logic on ViewModel, which shouldnt have any logic inside. 2-) By connecting the View model with logic inside to the xml, you have done nothing but pointing code behind(MainForm.cs) to ViewModel.cs. Thank you again for your time and efford.
Outstanding explanation, it can’t get any better than this!
Too good
can able to understand what command is
My question is how is it knowing that it has to execute that command on Click only. Why not on hover or anything else. We have not mentioned click anywhere??? Please help.
Any lead??
Very useful lesson 👍 thank you
Very good tutorial.
I don't understand your example with print command. Why should we write the code with codebehind page three times. I don't think anyone is doing it. You just write once a print function and just call it three times in the events in the code behind page. By using commands you also have to call the command three times, just not in the code behind page but in the binding of the view. Correct me if you have another opinion
Very Helpful and theory is really good.
Great tutorial tbh, the way you explained it made perfect sense. Thanks!
Thank you a lot you have the talent of explanation
very thanks.. finally i understand view model...
you did not use the eventhandler "canExecuteChanged" anywhere...
very useful for beginners.Thank you so much.
It seems that Command is for Button click use case. Should Slider, ComboBox... use Command to eliminate the code behind?
I have a generic command that I've been using for years, which looks almost the same as yours. I wonder why Microsoft doesn't deliver this implementation instead of simply providing ICommand without any standard implementation.
This is a good example to illustrate my hesitation while I'm learning C# and .NET in general: I can see the author simplified the example to the best level possible, but I still can not comprehend as a generally logically thinking human beeing - why the hell the authors of this computer language made it so that to implement a simple thing one would reasonably hope to have done in a few lines of code and in just a few property settings hwere needed, it requires tens of lines of code, a number of entities and multi-level representation of the logically same thing (with repetition of entities like onion layers) ??
whose sick mind could invent such a programming philosophy I keep wondering?
To me its an ideal source of many mistakes and bugs a general piece of SW is notorious with, or when finally bug-fixed and tested ok than explains why it costs so much to develop software (when another programmer struggles to understand what the author meant to do here and there if not properly commented in the code or without documentation). Doesn't the general science rule (citation from Einstein or someone else?) state that the right thing should be short and clear.
To me the code should better be longer in terms of lines but more humanly understandable, to hell with these multiple layers of abstraction:))
Or what is this, a conspiracy? - make it difficult to understand for others and profit from your competitive advantage - artificially created logical constructs? :))
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH thank you, you truly made me laugh from the bottom of my heart XD
It's not to make things harder. It's used to decouple UI from the business logic. And though for this easy MessageBox.Show he has so much overhead in this example, the overhead is static here. He will be able to reuse that (Relay)Command class (and possibly ViewModelBase class). It's a lot of overhead for a simple and small WPF application, but it's the opposite when the application comes enormous and you want to couple your logic to a different UI.
The MVVM design pattern is honestly not that complicated, though i think the documentation of it by many people seems disorganised. Once you understand that INotifyPropertyChanged is simply an event in the Setter methods of properties that helps UI to know when to re-get the value of that property after it has been set to something else and that commands are really just a public delegate void (object) that you pass a function into and can call from your UI using
Awesome Its very helpfull Thank You....
Excelente explicación
thank for giving a wonderful video on command
Welcome....
Thank you very much for your video, I have one question please , till now I can’t understand that, your command has als default Click event , can I build command working with other events? For example hover or any other event?
Thank you so much
I have a "ViewModel" does not exist in the namespace "clr-namespace" error.
Hey i got the same error!!
Thanks for the wonderful video, I understood MVVM concept and I did practical as well, my both class files are as like yours still, I am getting the error that my namespace does not find the class. i tried to solve several ways have not got any luck . would you please suggest any solution to cure this problem !!!
You can set the Datacontext of the window from the UI using
If you have your viewmodel in a folder then you could create a new xml namespace:
xmlns:nameofchoice="clr-namespace:SolutionName.FolderName"
pls sharesome idea about RoutedCommand and difference between Relay and RoutedCommand..
HI good one...Can we get the vieo related to difference between ICommand and Routed Events ...and when to implement it..Please make a video for this
Hello, excellent video; Can you upload similar video in "Visual Basic" language applied in 2 or more windows?
Hi, I am new to WPF. Can somebody explain me how actually this code works. Not able to understand how executeMethod of ViewModel is executed.
we have not implemented EventHandler CanExecuteChanged... Why?
excellent explaination of complex in easy way. I want to point out why canexecutemethod return true in both command class and viewmodel class.
Thank you for explanation, Can you please make video how to hide fields on click of button/Radio button during runtime in MVVM
I faced an error when trying to use
it's saying: The name ViewModel does not exist in the clr-namespace:Sample
I cleaned the solution and rebuild it, it got fixed ^^.
Hii Sir,
Your videos are great to learn..
But i have one doubt is that, how to copy observable collection to clipboard in WPF
Please help
Gracias.
Why we have not use data soure
Please provide more examples wpf with mvvm
Thanks!
I just don't get commands, especially the claim that there is no code behind, and then proceed to write 2 full classes of code behind.
So event = Add message box.
And command = walk a mile and then add message box.
AWESOME!!!!
When writing code in Codebehind page is very simple then why to use these many lines of coding just to call single click event?
You are right in this simple case it's easier and quicker to write it into the CodeBehind of the View. But we are working towards understanding and using the MVVM pattern which is fundamentally the separation of the Business Logic code and the UI code. Perhaps you should re-watch the "MVVM Pattern in WPF" video again for the explanation of why we want to do this.
Can you please share the codes as well for the benfit of time
Yes will share the same..
@@dotnetskoool5809 great thx a lot . Tutorials are really awesome and simple
where can i get the code. Did you get time to upload the code?
Please check the video discription. Thanks
@@dotnetskoool5809 : you nailed it thx for sharing.It saved lot of time
public ClickViewModel()
{
MyCommand = new OnclickCommand(ExecuteMethod, canExecuteMethod);
}
This, above parameter value pass error , how to resolve problem
Error occures
looks like class name you use view model instead of ViewModel
Thank you for helpful video.? for asking question to you ,can you share your email?