How to button_click in C# WPF MVVM style | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to button_click in C# WPF MVVM style

I am learning c# with WPF. I have been using winforms for a long time. I am trying to create my projects MVVM style. I just go stuck on button_click. In winform you click a button and get a button1_Click event. In WPF you can do the same, Click="button_Click" But this doesn't seem to be proper MVVM. Can some one explain to how bind a button to a method using MVVM ? What are the advantages of doing so ?

20th May 2019, 8:31 PM
sneeze
sneeze - avatar
2 Answers
+ 4
Advantage: https://www.c-sharpcorner.com/UploadFile/nipuntomar/mvvm-in-wpf/ MVVM is a way of creating client applications that leverages core features of the WPF platform, allows for simple unit testing of application functionality, and helps developers and designers work together with less technical difficulties Tutorial: https://www.tutorialspoint.com/mvvm/
21st May 2019, 12:16 AM
Gordon
Gordon - avatar
0
Thanks. Nice to see MVP, MVC and MVVM be explained in one article. https://www.tutorialspoint.com/mvvm/mvvm_view_viewmodel_communication.htm In the tutorialspoint tutorial I get stuck when they talk about ICommand. They create an extra class to handle Commands, which is not a View, ViewModel or Model. DeleteCommand = new MyICommand(OnDelete, CanDelete); https://www.codeproject.com/Articles/274982/Commands-in-MVVM To get unstuck, I got in to reading this article. Which handles commands in a much easier way. simpleCommand = new Command(DoSimpleCommand); Is this MVVM as well ? Would it be correct to do it this way ? What would be disadvantages of doing it this way ?
21st May 2019, 9:22 PM
sneeze
sneeze - avatar