In this article I am going to add commanding to
the earlier post http://www.c-sharpcorner.com/UploadFile/Mahadesh/8807/.
Lets take a copy of the code created in the previous article . We would be doing
some modifications to add the Commanding.
Lets start with the PeopleViewModel.cs
We need to add a new class say UpdatePersonCommand. I would place this class in
public class UpdatePersonCommand :
if (parameter !=
event EventHandler CanExecuteChanged;
// We have some work to do here
Let me also add my command:
Let me now modify the MainPage.xaml.cs.
I will change the
Button_Click handler as shown below:
private void Button_Click(object
sender, RoutedEventArgs e)
What I do is just call the Execute on the Update Command which would modify my
As can be seen I pass the PageViewModel Instance in the execute method.
Nothing changes in the xaml code.
Just call the UpdatePerson in the Execute of the
(parameter as PeopleViewModel).UpdatePerson();
Run the project. It works the same way.
Thanks. Happy coding.