I am building a simple Calculator application. I’m also learning how to apply the MVVM pattern in my app.
I would like each one of the “Digit” buttons of my calculator to bind to the same Command, where they would only differ in the digit (Text) of the button that raised the command.
For example, When button “1” is clicked, i would like to receive the notification about it, extract “1” from the Sender’s property, and continue the rest of the work needed.
This allows me to define a single method instead of 10 different handlers.
This is not possible as far as what i’ve seen in all MVVM tutorials till now, since the Command binding does not provide all this information to me when binding to the actual method that will handle the click.
Is there any way to easily do what i require?
Assuming I understand what you’re trying to do, you can use the
CommandParameterproperty to let different buttons supply values to the same command. For example:And in your command’s delegate method: